Keyboard Input
Functions
initialization functions
promting
key press/release handlers
- keyboardSetKeyPressHandler
- keyboardSetKeyReleaseHandler
- keyboardResetKeyPressHandler
- keyboardResetKeyReleaseHandler
convert scancode <=> letter
shortcuts handling functions
type defs
Initialization functions
keyboardInit
>> Syntax:
>> Description:
initializes the keyboard driver by setting the keyboard buffer the current tty keyboard buffer, and default to the US keyboard layout.
keyboardSetLayout
>> Syntax:
>> Description:
Sets the keyboard layout to the provided layout (_kbdLayout).
keyboardSetBuffer
>> Syntax:
>> Description:
Sets the keyboard buffer to the provided buffer (_kbdBuffer).
keyboardClearBuffer
>> Syntax:
>> Description:
Clears the keyboard buffer.
Promting
prompt
>> Syntax:
>> Description:
Prompts the user with the provided message and waits for the user to enter a string of characters, which will be stored in the provided buffer.
>> Parameters:
- promtMessage: The message to be displayed to the user.
- buffer: The buffer to store the user input.
>> Returns:
The buffer containing the user input.
>> Note:
- can be interrupted with (interruptPrompting).
- buffer overflow ?!
interruptPrompting
>> Syntax:
>> Description:
Interrupts the current prompting operation.
Key press/release handlers
keyboardSetKeyPressHandler
>> Syntax:
>> Description:
Sets the key press handler to the provided handler (onKeyPressHanlder).
keyboardSetKeyReleaseHandler
>> Syntax:
>> Description:
Sets the key release handler to the provided handler (onKeyReleaseHanlder).
keyboardResetKeyPressHandler
>> Syntax:
>> Description:
Resets the key press handler to the default handler (tty compatible).
keyboardResetKeyReleaseHandler
>> Syntax:
>> Description:
Resets the key release handler to the default handler (tty compatible).
Convert scancode <=> letter
keyboardGetScancode
>> Syntax:
>> Description:
Returns the scancode of the provided letter.
keyboardGetLetter
>> Syntax:
>> Description:
Returns the letter of the provided scancode.
Shortcuts handling functions
shortcutsReset
>> Syntax:
>> Description:
Resets all the shortcuts.
setShortcut
>> Syntax:
>> Description:
Sets the provided shortcut (_shortcut) to the provided handler (onShortcutHandler).
type defs
_kbdBuffer
typedef struct kbdBuffer {
uint8_t buffer[MAX_KEYBOARD_BUFFER];
uint32_t index;
uint32_t size;
} _kbdBuffer;
>> Description:
The _kbdBuffer struct represents a keyboard buffer.
>> Fields:
- uint8_t buffer[MAX_KEYBOARD_BUFFER]: the buffer to store the keyboard input.
- uint32_t index: the current index in the buffer.
- uint32_t size: the size of the buffer.
onKeyPressHanlder
>> Description:
The onKeyPressHanlder is a function pointer type that represents a key press handler.
>> Parameters:
- uint8_t: pressed letter. (!= scancode)
onKeyReleaseHanlder
>> Description:
The onKeyReleaseHanlder is a function pointer type that represents a key release handler.
>> Parameters:
- uint8_t: the scancode of the released key.
_shortcut
typedef struct shortcut {
char key;
uint8_t flagedModifiers;
onShortcutHandler handler;
} _shortcut;
>> Description:
The _shortcut struct represents a keyboard shortcut.
>> Fields:
- char key: the key of the shortcut.
- uint8_t flagedModifiers: the modifiers of the shortcut. (ctrl | alt | shift)
- onShortcutHandler handler: the handler of the shortcut.
onShortcutHandler
>> Description:
The onShortcutHandler is a function pointer type that represents a shortcut handler.
_kbdLayout
>> Description:
- The _kbdLayout union represents a keyboard layout.
- the keyboard layout can be accessed as a struct (keyboardViews) or as an array of uint8_t pointers.
- keyboard layouts are declared in the keyboardDriver.c file.