Home Contents | # keyboard.key | Keyboard | Core4 Lua Event System

## SYNOPSIS

#include <lua/scancode.lh>
kbdhandle.key = function(kbdhandle, codepoint, scancode, modifiers)

## DESCRIPTION

Reports a typed key on a keyboard or keypad. The parameter codepoint contains the unicode value of the key. Common keyboard processing has been applied, like auto-repeat, uppercase/lowercase, etc.

The scancode value depends on the source reporting the key. For matrix keypads, this is the index of the key in the lookup table + 0x90000 (HUT 9 = Buttons).
For USB keyboards, this is the USB HID scancode from the USB standard + 0x70000 (HUT 7 = Keyboard). The lua/scancode.lh defines these values. Use the SCANCODE(KEY_xxx) macro for processing.

modifiers reports the modifiers keys (e.g. Shift, Ctrl, ...) that where held when the key was typed. This is an integer values whose bits indicate none or more modifiers. The modifiers are defined in the lua/scancode.lh header file as MOD_xxx macros.

## NOTES

Callbacks are called from within event:poll().

## EXAMPLE

> > > > > > > >
app = event.new() kbd = keyboard.new(app) kbd.key = function(kbd, codepoint) print(codepoint) end while true do app:poll() end

When typing the keys 1, 2, 3 it will print:

49 50 51

## SEE ALSO

keyboard:clearCallbacks, keyboard.event, keyboard:setMap, keyboard:setCountry