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

## SYNOPSIS

#include <lua/scancode.lh>
kbdhandle.event = function(kbdhandle, event)

## DESCRIPTION

Reports a typed key on a keyboard or keypad. The parameter event receives a table with the raw event data, and also the processed key including auto-repeat, uppercase/lowercase, etc.

location | Identifies the keyboard/keypad. For a matrix keypad, this is 0. A USB keyboard reports its USB location ID, which is basically the number of the USB port where it is connected to.
scancode | The scancode of 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.
value | Indicates key down (0), key up (1) or key repeat (2).
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.
unicode | The processed unicode value. Same value as reported to keyboard.key.

## NOTES

Callbacks are called from within event:poll().

## EXAMPLE

> > > > > > > > > > > > >
app = event.new() kbd = keyboard.new(app) kbd.event = function(kbd, event) print("KEYBOARD EVENT") for k,v in pairs(event) do print (k,v) end end while true do app:poll() end

When typing and releasing the key 1 on an USB keyboard plugged into USB connector 2 it will print:

KEYBOARD EVENT value 0 unicode 49 modifiers 4096 scancode 458782 location 2 KEYBOARD EVENT value 1 unicode 49 modifiers 4096 scancode 458782 location 2

## SEE ALSO

keyboard:clearCallbacks, keyboard.key, keyboard:setMap, keyboard:setCountry