Ultibo API
C/C++ API for Ultibo Core
Loading...
Searching...
No Matches
keyboard.h File Reference

Go to the source code of this file.

Data Structures

struct  _KEYBOARD_DATA
struct  _KEYBOARD_BUFFER
struct  _KEYBOARD_DEVICE
struct  _USB_HID_DESCRIPTOR

Macros

#define KEYBOARD_NAME_PREFIX   "Keyboard"
 Name prefix for Keyboard Devices.
#define KEYBOARD_TYPE_NONE   0
#define KEYBOARD_TYPE_USB   1
#define KEYBOARD_TYPE_PS2   2
#define KEYBOARD_TYPE_SERIAL   3
#define KEYBOARD_TYPE_MAX   3
#define KEYBOARD_STATE_DETACHED   0
#define KEYBOARD_STATE_DETACHING   1
#define KEYBOARD_STATE_ATTACHING   2
#define KEYBOARD_STATE_ATTACHED   3
#define KEYBOARD_STATE_MAX   3
#define KEYBOARD_FLAG_NONE   0x00000000
#define KEYBOARD_FLAG_NON_BLOCK   0x00000001
 If set device reads are non blocking (Also supported in Flags parameter of KeyboardReadEx).
#define KEYBOARD_FLAG_DIRECT_READ   0x00000002
 If set device writes keyboard data to its local buffer which must be read using KeyboardDeviceRead.
#define KEYBOARD_FLAG_PEEK_BUFFER   0x00000004
 Peek at the buffer to see if any data is available, don't remove it (Used only in Flags parameter of KeyboardReadEx).
#define KEYBOARD_FLAG_MASK   KEYBOARD_FLAG_NON_BLOCK | KEYBOARD_FLAG_DIRECT_READ | KEYBOARD_FLAG_PEEK_BUFFER
#define KEYBOARD_CONTROL_GET_FLAG   1
 Get Flag.
#define KEYBOARD_CONTROL_SET_FLAG   2
 Set Flag.
#define KEYBOARD_CONTROL_CLEAR_FLAG   3
 Clear Flag.
#define KEYBOARD_CONTROL_FLUSH_BUFFER   4
 Flush Buffer.
#define KEYBOARD_CONTROL_GET_LED   5
 Get LED.
#define KEYBOARD_CONTROL_SET_LED   6
 Set LED.
#define KEYBOARD_CONTROL_CLEAR_LED   7
 Clear LED.
#define KEYBOARD_CONTROL_GET_REPEAT_RATE   8
 Get Repeat Rate.
#define KEYBOARD_CONTROL_SET_REPEAT_RATE   9
 Set Repeat Rate.
#define KEYBOARD_CONTROL_GET_REPEAT_DELAY   10
 Get Repeat Delay.
#define KEYBOARD_CONTROL_SET_REPEAT_DELAY   11
 Set Repeat Delay.
#define KEYBOARD_LED_NONE   0x00000000
#define KEYBOARD_LED_NUMLOCK   0x00000001
#define KEYBOARD_LED_CAPSLOCK   0x00000002
#define KEYBOARD_LED_SCROLLLOCK   0x00000004
#define KEYBOARD_LED_COMPOSE   0x00000008
#define KEYBOARD_LED_KANA   0x00000010
#define KEYBOARD_LED_MASK   KEYBOARD_LED_NUMLOCK | KEYBOARD_LED_CAPSLOCK | KEYBOARD_LED_SCROLLLOCK | KEYBOARD_LED_COMPOSE | KEYBOARD_LED_KANA
#define KEYBOARD_BUFFER_SIZE   512
#define KEYBOARD_REPEAT_RATE   40
 40msec -> 25cps
#define KEYBOARD_REPEAT_DELAY   10
 10 x KEYBOARD_REPEAT_RATE = 400msec initial delay before repeat
#define KEYBOARD_LEFT_CTRL   0x00000001
 The Left Control key is pressed.
#define KEYBOARD_LEFT_SHIFT   0x00000002
 The Left Shift key is pressed.
#define KEYBOARD_LEFT_ALT   0x00000004
 The Left Alt key is pressed.
#define KEYBOARD_LEFT_GUI   0x00000008
 The Left GUI (or Windows) key is pressed.
#define KEYBOARD_RIGHT_CTRL   0x00000010
 The Right Control key is pressed.
#define KEYBOARD_RIGHT_SHIFT   0x00000020
 The Right Shift key is pressed.
#define KEYBOARD_RIGHT_ALT   0x00000040
 The Right Alt key is pressed.
#define KEYBOARD_RIGHT_GUI   0x00000080
 The Right GUI (or Windows) key is pressed.
#define KEYBOARD_NUM_LOCK   0x00000100
 Num Lock is currently on.
#define KEYBOARD_CAPS_LOCK   0x00000200
 Caps Lock is currently on.
#define KEYBOARD_SCROLL_LOCK   0x00000400
 Scroll Lock is currently on.
#define KEYBOARD_COMPOSE   0x00000800
 Compose is currently on.
#define KEYBOARD_KANA   0x00001000
 Kana is currently on.
#define KEYBOARD_KEYUP   0x00002000
 The key state changed to up.
#define KEYBOARD_KEYDOWN   0x00004000
 The key state changed to down.
#define KEYBOARD_KEYREPEAT   0x00008000
 The key is being repeated.
#define KEYBOARD_DEADKEY   0x00010000
 The key is a being handled as a deadkey.
#define KEYBOARD_ALTGR   0x00020000
 The AltGr key is pressed (Normally also Right Alt but may be Ctrl-Alt).
#define USB_HID_SUBCLASS_NONE   0
 Section 4.2.
#define USB_HID_SUBCLASS_BOOT   1
 Section 4.2.
#define USB_HID_BOOT_PROTOCOL_NONE   0
 Section 4.3.
#define USB_HID_BOOT_PROTOCOL_KEYBOARD   1
 Section 4.3.
#define USB_HID_BOOT_PROTOCOL_MOUSE   2
 Section 4.3.
#define USB_HID_DESCRIPTOR_TYPE_HID   0x21
 Section 7.1.
#define USB_HID_DESCRIPTOR_TYPE_REPORT   0x22
 Section 7.1.
#define USB_HID_DESCRIPTOR_TYPE_PHYSICAL_DESCRIPTOR   0x23
 Section 7.1.
#define USB_HID_REQUEST_GET_REPORT   0x01
 Section 7.2.
#define USB_HID_REQUEST_GET_IDLE   0x02
 Section 7.2.
#define USB_HID_REQUEST_GET_PROTOCOL   0x03
 Section 7.2.
#define USB_HID_REQUEST_SET_REPORT   0x09
 Section 7.2.
#define USB_HID_REQUEST_SET_IDLE   0x0A
 Section 7.2.
#define USB_HID_REQUEST_SET_PROTOCOL   0x0B
 Section 7.2.
#define USB_HID_PROTOCOL_BOOT   0
 Section 7.2.5.
#define USB_HID_PROTOCOL_REPORT   1
 Section 7.2.5.
#define USB_HID_REPORT_INPUT   1
 Section 7.2.1.
#define USB_HID_REPORT_OUTPUT   2
 Section 7.2.1.
#define USB_HID_REPORT_FEATURE   3
 Section 7.2.1.
#define USB_HID_REPORTID_NONE   0
 Section 7.2.1.
#define USB_HID_BOOT_LEFT_CTRL   (1 << 0)
#define USB_HID_BOOT_LEFT_SHIFT   (1 << 1)
#define USB_HID_BOOT_LEFT_ALT   (1 << 2)
#define USB_HID_BOOT_LEFT_GUI   (1 << 3)
#define USB_HID_BOOT_RIGHT_CTRL   (1 << 4)
#define USB_HID_BOOT_RIGHT_SHIFT   (1 << 5)
#define USB_HID_BOOT_RIGHT_ALT   (1 << 6)
#define USB_HID_BOOT_RIGHT_GUI   (1 << 7)
#define USB_HID_BOOT_REPORT_SIZE   8
 Appendix B of HID Device Class Definition 1.11.
#define USB_HID_BOOT_NUMLOCK_LED   (1 << 0)
#define USB_HID_BOOT_CAPSLOCK_LED   (1 << 1)
#define USB_HID_BOOT_SCROLLLOCK_LED   (1 << 2)
#define USB_HID_BOOT_COMPOSE_LED   (1 << 3)
#define USB_HID_BOOT_KANA_LED   (1 << 4)
#define USB_HID_BOOT_LEDMASK   USB_HID_BOOT_NUMLOCK_LED | USB_HID_BOOT_CAPSLOCK_LED | USB_HID_BOOT_SCROLLLOCK_LED | USB_HID_BOOT_COMPOSE_LED | USB_HID_BOOT_KANA_LED
#define USB_HID_BOOT_OUTPUT_SIZE   1
 Appendix B of HID Device Class Definition 1.11.
#define USB_HID_BOOT_USAGE_NUMLOCK   SCAN_CODE_NUMLOCK
 83
#define USB_HID_BOOT_USAGE_CAPSLOCK   SCAN_CODE_CAPSLOCK
 57
#define USB_HID_BOOT_USAGE_SCROLLLOCK   SCAN_CODE_SCROLLLOCK
 71

Typedefs

typedef struct _KEYBOARD_DATA KEYBOARD_DATA
typedef struct _KEYBOARD_BUFFER KEYBOARD_BUFFER
typedef struct _KEYBOARD_DEVICE KEYBOARD_DEVICE
typedef uint32_t STDCALL(* keyboard_enumerate_cb) (KEYBOARD_DEVICE *keyboard, void *data)
typedef uint32_t STDCALL(* keyboard_notification_cb) (DEVICE *device, void *data, uint32_t notification)
typedef uint32_t STDCALL(* keyboard_device_get_proc) (KEYBOARD_DEVICE *keyboard, uint16_t *keycode)
typedef uint32_t STDCALL(* keyboard_device_read_proc) (KEYBOARD_DEVICE *keyboard, void *buffer, uint32_t size, uint32_t *count)
typedef uint32_t STDCALL(* keyboard_device_control_proc) (KEYBOARD_DEVICE *keyboard, int request, size_t argument1, size_t *argument2)
typedef struct _USB_HID_DESCRIPTOR USB_HID_DESCRIPTOR

Functions

uint32_t STDCALL keyboard_get (uint16_t *keycode)
 Get the first key code from the global keyboard buffer.
uint32_t STDCALL keyboard_peek (void)
 Peek at the global keyboard buffer to see if any data packets are ready.
uint32_t STDCALL keyboard_read (void *buffer, uint32_t size, uint32_t *count)
 Read keyboard data packets from the global keyboard buffer.
uint32_t STDCALL keyboard_read_ex (void *buffer, uint32_t size, uint32_t flags, uint32_t *count)
 Read keyboard data packets from the global keyboard buffer.
uint32_t STDCALL keyboard_put (uint16_t scancode, uint16_t keycode, uint32_t modifiers)
 Put a scan code and key code in the global keyboard buffer.
uint32_t STDCALL keyboard_write (void *buffer, uint32_t size, uint32_t count)
 Write keyboard data packets to the global keyboard buffer.
uint32_t STDCALL keyboard_flush (void)
 Flush the contents of the global keyboard buffer.
uint32_t STDCALL keyboard_device_get (KEYBOARD_DEVICE *keyboard, uint16_t *keycode)
 Get the first key code from the buffer of the specified keyboard.
uint32_t STDCALL keyboard_device_read (KEYBOARD_DEVICE *keyboard, void *buffer, uint32_t size, uint32_t *count)
 Read keyboard data packets from the buffer of the specified keyboard.
uint32_t STDCALL keyboard_device_control (KEYBOARD_DEVICE *keyboard, int request, size_t argument1, size_t *argument2)
 Perform a control request on the specified keyboard device.
uint32_t STDCALL keyboard_device_set_state (KEYBOARD_DEVICE *keyboard, uint32_t state)
 Set the state of the specified keyboard and send a notification.
KEYBOARD_DEVICE *STDCALL keyboard_device_create (void)
 Create a new Keyboard device entry.
KEYBOARD_DEVICE *STDCALL keyboard_device_create_ex (uint32_t size)
 Create a new Keyboard device entry.
uint32_t STDCALL keyboard_device_destroy (KEYBOARD_DEVICE *keyboard)
 Destroy an existing Keyboard device entry.
uint32_t STDCALL keyboard_device_register (KEYBOARD_DEVICE *keyboard)
 Register a new Keyboard device in the Keyboard table.
uint32_t STDCALL keyboard_device_deregister (KEYBOARD_DEVICE *keyboard)
 Deregister a Keyboard device from the Keyboard table.
KEYBOARD_DEVICE *STDCALL keyboard_device_find (uint32_t keyboardid)
 Find a keyboard device by ID in the keyboard table.
KEYBOARD_DEVICE *STDCALL keyboard_device_find_by_name (const char *name)
 Find a keyboard device by name in the keyboard table.
KEYBOARD_DEVICE *STDCALL keyboard_device_find_by_description (const char *description)
 Find a keyboard device by description in the keyboard table.
uint32_t STDCALL keyboard_device_enumerate (keyboard_enumerate_cb callback, void *data)
 Enumerate all keyboard devices in the keyboard table.
uint32_t STDCALL keyboard_device_notification (KEYBOARD_DEVICE *keyboard, keyboard_notification_cb callback, void *data, uint32_t notification, uint32_t flags)
 Register a notification for keyboard device changes.
uint32_t STDCALL keyboard_get_count (void)
 Get the current keyboard count.
KEYBOARD_DEVICE *STDCALL keyboard_device_check (KEYBOARD_DEVICE *keyboard)
 Check if the supplied Keyboard is in the keyboard table.
uint32_t STDCALL keyboard_device_type_to_string (uint32_t keyboardtype, char *string, uint32_t len)
uint32_t STDCALL keyboard_device_state_to_string (uint32_t keyboardstate, char *string, uint32_t len)
uint32_t STDCALL keyboard_device_state_to_notification (uint32_t state)
 Convert a Keyboard state value into the notification code for device notifications.
uint16_t STDCALL keyboard_remap_ctrl_code (uint16_t keycode, uint16_t charcode)
 Remap Ctrl-<Key> combinations to ASCII control codes.
BOOL STDCALL keyboard_remap_key_code (uint16_t scancode, uint16_t keycode, uint8_t *charcode, uint32_t modifiers)
 Remap the SCAN_CODE_* and KEY_CODE_* values to DOS compatible scan codes.
BOOL STDCALL keyboard_remap_scan_code (uint16_t scancode, uint16_t keycode, uint8_t *charcode, uint32_t modifiers)
 Remap the SCAN_CODE_* and KEY_CODE_* values to DOS compatible scan codes.
uint32_t STDCALL keyboard_insert_data (KEYBOARD_DEVICE *keyboard, KEYBOARD_DATA *data, BOOL signal)
 Insert a TKeyboardData entry into the keyboard buffer (Direct or Global).

Variables

struct _USB_HID_DESCRIPTOR PACKED

Macro Definition Documentation

◆ KEYBOARD_NAME_PREFIX

#define KEYBOARD_NAME_PREFIX   "Keyboard"

Name prefix for Keyboard Devices.

Keyboard specific constants

◆ KEYBOARD_TYPE_NONE

#define KEYBOARD_TYPE_NONE   0

Keyboard Device Types

◆ KEYBOARD_TYPE_USB

#define KEYBOARD_TYPE_USB   1

◆ KEYBOARD_TYPE_PS2

#define KEYBOARD_TYPE_PS2   2

◆ KEYBOARD_TYPE_SERIAL

#define KEYBOARD_TYPE_SERIAL   3

◆ KEYBOARD_TYPE_MAX

#define KEYBOARD_TYPE_MAX   3

◆ KEYBOARD_STATE_DETACHED

#define KEYBOARD_STATE_DETACHED   0

Keyboard Device States

◆ KEYBOARD_STATE_DETACHING

#define KEYBOARD_STATE_DETACHING   1

◆ KEYBOARD_STATE_ATTACHING

#define KEYBOARD_STATE_ATTACHING   2

◆ KEYBOARD_STATE_ATTACHED

#define KEYBOARD_STATE_ATTACHED   3

◆ KEYBOARD_STATE_MAX

#define KEYBOARD_STATE_MAX   3

◆ KEYBOARD_FLAG_NONE

#define KEYBOARD_FLAG_NONE   0x00000000

Keyboard Device Flags

◆ KEYBOARD_FLAG_NON_BLOCK

#define KEYBOARD_FLAG_NON_BLOCK   0x00000001

If set device reads are non blocking (Also supported in Flags parameter of KeyboardReadEx).

◆ KEYBOARD_FLAG_DIRECT_READ

#define KEYBOARD_FLAG_DIRECT_READ   0x00000002

If set device writes keyboard data to its local buffer which must be read using KeyboardDeviceRead.

◆ KEYBOARD_FLAG_PEEK_BUFFER

#define KEYBOARD_FLAG_PEEK_BUFFER   0x00000004

Peek at the buffer to see if any data is available, don't remove it (Used only in Flags parameter of KeyboardReadEx).

◆ KEYBOARD_FLAG_MASK

◆ KEYBOARD_CONTROL_GET_FLAG

#define KEYBOARD_CONTROL_GET_FLAG   1

Get Flag.

Keyboard Device Control Codes

◆ KEYBOARD_CONTROL_SET_FLAG

#define KEYBOARD_CONTROL_SET_FLAG   2

Set Flag.

◆ KEYBOARD_CONTROL_CLEAR_FLAG

#define KEYBOARD_CONTROL_CLEAR_FLAG   3

Clear Flag.

◆ KEYBOARD_CONTROL_FLUSH_BUFFER

#define KEYBOARD_CONTROL_FLUSH_BUFFER   4

Flush Buffer.

◆ KEYBOARD_CONTROL_GET_LED

#define KEYBOARD_CONTROL_GET_LED   5

Get LED.

◆ KEYBOARD_CONTROL_SET_LED

#define KEYBOARD_CONTROL_SET_LED   6

Set LED.

◆ KEYBOARD_CONTROL_CLEAR_LED

#define KEYBOARD_CONTROL_CLEAR_LED   7

Clear LED.

◆ KEYBOARD_CONTROL_GET_REPEAT_RATE

#define KEYBOARD_CONTROL_GET_REPEAT_RATE   8

Get Repeat Rate.

◆ KEYBOARD_CONTROL_SET_REPEAT_RATE

#define KEYBOARD_CONTROL_SET_REPEAT_RATE   9

Set Repeat Rate.

◆ KEYBOARD_CONTROL_GET_REPEAT_DELAY

#define KEYBOARD_CONTROL_GET_REPEAT_DELAY   10

Get Repeat Delay.

◆ KEYBOARD_CONTROL_SET_REPEAT_DELAY

#define KEYBOARD_CONTROL_SET_REPEAT_DELAY   11

Set Repeat Delay.

◆ KEYBOARD_LED_NONE

#define KEYBOARD_LED_NONE   0x00000000

Keyboard Device LEDs

◆ KEYBOARD_LED_NUMLOCK

#define KEYBOARD_LED_NUMLOCK   0x00000001

◆ KEYBOARD_LED_CAPSLOCK

#define KEYBOARD_LED_CAPSLOCK   0x00000002

◆ KEYBOARD_LED_SCROLLLOCK

#define KEYBOARD_LED_SCROLLLOCK   0x00000004

◆ KEYBOARD_LED_COMPOSE

#define KEYBOARD_LED_COMPOSE   0x00000008

◆ KEYBOARD_LED_KANA

#define KEYBOARD_LED_KANA   0x00000010

◆ KEYBOARD_LED_MASK

◆ KEYBOARD_BUFFER_SIZE

#define KEYBOARD_BUFFER_SIZE   512

Keyboard Buffer Size

◆ KEYBOARD_REPEAT_RATE

#define KEYBOARD_REPEAT_RATE   40

40msec -> 25cps

Keyboard Sampling Rate

◆ KEYBOARD_REPEAT_DELAY

#define KEYBOARD_REPEAT_DELAY   10

10 x KEYBOARD_REPEAT_RATE = 400msec initial delay before repeat

◆ KEYBOARD_LEFT_CTRL

#define KEYBOARD_LEFT_CTRL   0x00000001

The Left Control key is pressed.

Keyboard Data Definitions (Values for TKeyboardData.Modifiers)

◆ KEYBOARD_LEFT_SHIFT

#define KEYBOARD_LEFT_SHIFT   0x00000002

The Left Shift key is pressed.

◆ KEYBOARD_LEFT_ALT

#define KEYBOARD_LEFT_ALT   0x00000004

The Left Alt key is pressed.

◆ KEYBOARD_LEFT_GUI

#define KEYBOARD_LEFT_GUI   0x00000008

The Left GUI (or Windows) key is pressed.

◆ KEYBOARD_RIGHT_CTRL

#define KEYBOARD_RIGHT_CTRL   0x00000010

The Right Control key is pressed.

◆ KEYBOARD_RIGHT_SHIFT

#define KEYBOARD_RIGHT_SHIFT   0x00000020

The Right Shift key is pressed.

◆ KEYBOARD_RIGHT_ALT

#define KEYBOARD_RIGHT_ALT   0x00000040

The Right Alt key is pressed.

◆ KEYBOARD_RIGHT_GUI

#define KEYBOARD_RIGHT_GUI   0x00000080

The Right GUI (or Windows) key is pressed.

◆ KEYBOARD_NUM_LOCK

#define KEYBOARD_NUM_LOCK   0x00000100

Num Lock is currently on.

◆ KEYBOARD_CAPS_LOCK

#define KEYBOARD_CAPS_LOCK   0x00000200

Caps Lock is currently on.

◆ KEYBOARD_SCROLL_LOCK

#define KEYBOARD_SCROLL_LOCK   0x00000400

Scroll Lock is currently on.

◆ KEYBOARD_COMPOSE

#define KEYBOARD_COMPOSE   0x00000800

Compose is currently on.

◆ KEYBOARD_KANA

#define KEYBOARD_KANA   0x00001000

Kana is currently on.

◆ KEYBOARD_KEYUP

#define KEYBOARD_KEYUP   0x00002000

The key state changed to up.

◆ KEYBOARD_KEYDOWN

#define KEYBOARD_KEYDOWN   0x00004000

The key state changed to down.

◆ KEYBOARD_KEYREPEAT

#define KEYBOARD_KEYREPEAT   0x00008000

The key is being repeated.

◆ KEYBOARD_DEADKEY

#define KEYBOARD_DEADKEY   0x00010000

The key is a being handled as a deadkey.

◆ KEYBOARD_ALTGR

#define KEYBOARD_ALTGR   0x00020000

The AltGr key is pressed (Normally also Right Alt but may be Ctrl-Alt).

◆ USB_HID_SUBCLASS_NONE

#define USB_HID_SUBCLASS_NONE   0

Section 4.2.

USB Keyboard specific constants Note: The following constants are duplicated with the USBKeyboard unit for backwards compatibility HID Interface Subclass types (See USB HID v1.11 specification)

◆ USB_HID_SUBCLASS_BOOT

#define USB_HID_SUBCLASS_BOOT   1

Section 4.2.

◆ USB_HID_BOOT_PROTOCOL_NONE

#define USB_HID_BOOT_PROTOCOL_NONE   0

Section 4.3.

HID Interface Protocol types (See USB HID v1.11 specification)

◆ USB_HID_BOOT_PROTOCOL_KEYBOARD

#define USB_HID_BOOT_PROTOCOL_KEYBOARD   1

Section 4.3.

◆ USB_HID_BOOT_PROTOCOL_MOUSE

#define USB_HID_BOOT_PROTOCOL_MOUSE   2

Section 4.3.

◆ USB_HID_DESCRIPTOR_TYPE_HID

#define USB_HID_DESCRIPTOR_TYPE_HID   0x21

Section 7.1.

HID Class Descriptor Types (See USB HID v1.11 specification)

◆ USB_HID_DESCRIPTOR_TYPE_REPORT

#define USB_HID_DESCRIPTOR_TYPE_REPORT   0x22

Section 7.1.

◆ USB_HID_DESCRIPTOR_TYPE_PHYSICAL_DESCRIPTOR

#define USB_HID_DESCRIPTOR_TYPE_PHYSICAL_DESCRIPTOR   0x23

Section 7.1.

◆ USB_HID_REQUEST_GET_REPORT

#define USB_HID_REQUEST_GET_REPORT   0x01

Section 7.2.

HID Request types

◆ USB_HID_REQUEST_GET_IDLE

#define USB_HID_REQUEST_GET_IDLE   0x02

Section 7.2.

◆ USB_HID_REQUEST_GET_PROTOCOL

#define USB_HID_REQUEST_GET_PROTOCOL   0x03

Section 7.2.

◆ USB_HID_REQUEST_SET_REPORT

#define USB_HID_REQUEST_SET_REPORT   0x09

Section 7.2.

◆ USB_HID_REQUEST_SET_IDLE

#define USB_HID_REQUEST_SET_IDLE   0x0A

Section 7.2.

◆ USB_HID_REQUEST_SET_PROTOCOL

#define USB_HID_REQUEST_SET_PROTOCOL   0x0B

Section 7.2.

◆ USB_HID_PROTOCOL_BOOT

#define USB_HID_PROTOCOL_BOOT   0

Section 7.2.5.

HID Protocol types

◆ USB_HID_PROTOCOL_REPORT

#define USB_HID_PROTOCOL_REPORT   1

Section 7.2.5.

◆ USB_HID_REPORT_INPUT

#define USB_HID_REPORT_INPUT   1

Section 7.2.1.

HID Report types

◆ USB_HID_REPORT_OUTPUT

#define USB_HID_REPORT_OUTPUT   2

Section 7.2.1.

◆ USB_HID_REPORT_FEATURE

#define USB_HID_REPORT_FEATURE   3

Section 7.2.1.

◆ USB_HID_REPORTID_NONE

#define USB_HID_REPORTID_NONE   0

Section 7.2.1.

HID Report IDs

◆ USB_HID_BOOT_LEFT_CTRL

#define USB_HID_BOOT_LEFT_CTRL   (1 << 0)

HID Boot Protocol Modifier bits

◆ USB_HID_BOOT_LEFT_SHIFT

#define USB_HID_BOOT_LEFT_SHIFT   (1 << 1)

◆ USB_HID_BOOT_LEFT_ALT

#define USB_HID_BOOT_LEFT_ALT   (1 << 2)

◆ USB_HID_BOOT_LEFT_GUI

#define USB_HID_BOOT_LEFT_GUI   (1 << 3)

◆ USB_HID_BOOT_RIGHT_CTRL

#define USB_HID_BOOT_RIGHT_CTRL   (1 << 4)

◆ USB_HID_BOOT_RIGHT_SHIFT

#define USB_HID_BOOT_RIGHT_SHIFT   (1 << 5)

◆ USB_HID_BOOT_RIGHT_ALT

#define USB_HID_BOOT_RIGHT_ALT   (1 << 6)

◆ USB_HID_BOOT_RIGHT_GUI

#define USB_HID_BOOT_RIGHT_GUI   (1 << 7)

◆ USB_HID_BOOT_REPORT_SIZE

#define USB_HID_BOOT_REPORT_SIZE   8

Appendix B of HID Device Class Definition 1.11.

HID Boot Protocol Report data

◆ USB_HID_BOOT_NUMLOCK_LED

#define USB_HID_BOOT_NUMLOCK_LED   (1 << 0)

HID Boot Protocol Output bits

◆ USB_HID_BOOT_CAPSLOCK_LED

#define USB_HID_BOOT_CAPSLOCK_LED   (1 << 1)

◆ USB_HID_BOOT_SCROLLLOCK_LED

#define USB_HID_BOOT_SCROLLLOCK_LED   (1 << 2)

◆ USB_HID_BOOT_COMPOSE_LED

#define USB_HID_BOOT_COMPOSE_LED   (1 << 3)

◆ USB_HID_BOOT_KANA_LED

#define USB_HID_BOOT_KANA_LED   (1 << 4)

◆ USB_HID_BOOT_LEDMASK

◆ USB_HID_BOOT_OUTPUT_SIZE

#define USB_HID_BOOT_OUTPUT_SIZE   1

Appendix B of HID Device Class Definition 1.11.

HID Boot Protocol Output data

◆ USB_HID_BOOT_USAGE_NUMLOCK

#define USB_HID_BOOT_USAGE_NUMLOCK   SCAN_CODE_NUMLOCK

83

◆ USB_HID_BOOT_USAGE_CAPSLOCK

#define USB_HID_BOOT_USAGE_CAPSLOCK   SCAN_CODE_CAPSLOCK

57

◆ USB_HID_BOOT_USAGE_SCROLLLOCK

#define USB_HID_BOOT_USAGE_SCROLLLOCK   SCAN_CODE_SCROLLLOCK

71

Typedef Documentation

◆ KEYBOARD_DATA

typedef struct _KEYBOARD_DATA KEYBOARD_DATA

Keyboard specific types Keyboard Data

◆ KEYBOARD_BUFFER

Keyboard Buffer

◆ KEYBOARD_DEVICE

Keyboard Device

◆ keyboard_enumerate_cb

typedef uint32_t STDCALL(* keyboard_enumerate_cb) (KEYBOARD_DEVICE *keyboard, void *data)

Keyboard Enumeration Callback

◆ keyboard_notification_cb

typedef uint32_t STDCALL(* keyboard_notification_cb) (DEVICE *device, void *data, uint32_t notification)

Keyboard Notification Callback

◆ keyboard_device_get_proc

typedef uint32_t STDCALL(* keyboard_device_get_proc) (KEYBOARD_DEVICE *keyboard, uint16_t *keycode)

Keyboard Device Methods

◆ keyboard_device_read_proc

typedef uint32_t STDCALL(* keyboard_device_read_proc) (KEYBOARD_DEVICE *keyboard, void *buffer, uint32_t size, uint32_t *count)

◆ keyboard_device_control_proc

typedef uint32_t STDCALL(* keyboard_device_control_proc) (KEYBOARD_DEVICE *keyboard, int request, size_t argument1, size_t *argument2)

◆ USB_HID_DESCRIPTOR

USB Keyboard specific types Note: The following structure is duplicated with the USBKeyboard unit for backwards compatibility USB HID Descriptor

USB Mouse specific types Note: The following structure is duplicated with the USBMouse unit for backwards compatibility USB HID Descriptor

Function Documentation

◆ keyboard_get()

uint32_t STDCALL keyboard_get ( uint16_t * keycode)

Get the first key code from the global keyboard buffer.

Keyboard Functions

Parameters
KeyCodeThe returned key code read from the buffer (eg KEY_CODE_A)
Returns
ERROR_SUCCESS if completed or another error code on failure
Note
Key code is the value translated from the scan code using the current keymap it may not be a character code and it may include non printable characters.

To translate a key code to a character call KeymapGetCharCode()

◆ keyboard_peek()

uint32_t STDCALL keyboard_peek ( void )

Peek at the global keyboard buffer to see if any data packets are ready.

Returns
ERROR_SUCCESS if packets are ready, ERROR_NO_MORE_ITEMS if not or another error code on failure

◆ keyboard_read()

uint32_t STDCALL keyboard_read ( void * buffer,
uint32_t size,
uint32_t * count )

Read keyboard data packets from the global keyboard buffer.

Parameters
BufferPointer to a buffer to copy the keyboard data packets to
SizeThe size of the buffer in bytes (Must be at least TKeyboardData or greater)
CountThe number of keyboard data packets copied to the buffer
Returns
ERROR_SUCCESS if completed or another error code on failure

◆ keyboard_read_ex()

uint32_t STDCALL keyboard_read_ex ( void * buffer,
uint32_t size,
uint32_t flags,
uint32_t * count )

Read keyboard data packets from the global keyboard buffer.

Parameters
BufferPointer to a buffer to copy the keyboard data packets to
SizeThe size of the buffer in bytes (Must be at least TKeyboardData or greater)
FlagsThe flags to use for the read (eg KEYBOARD_FLAG_NON_BLOCK)
CountThe number of keyboard data packets copied to the buffer
Returns
ERROR_SUCCESS if completed or another error code on failure

◆ keyboard_put()

uint32_t STDCALL keyboard_put ( uint16_t scancode,
uint16_t keycode,
uint32_t modifiers )

Put a scan code and key code in the global keyboard buffer.

Parameters
ScanCodeThe scan code to write to the buffer (eg SCAN_CODE_A)
KeyCodeThe key code to write to the buffer (eg KEY_CODE_A)
ModifiersThe modifier keys to write to the buffer (eg KEYBOARD_LEFT_CTRL)
Returns
ERROR_SUCCESS if completed or another error code on failure

◆ keyboard_write()

uint32_t STDCALL keyboard_write ( void * buffer,
uint32_t size,
uint32_t count )

Write keyboard data packets to the global keyboard buffer.

Parameters
BufferPointer to a buffer to copy the keyboard data packets from
SizeThe size of the buffer in bytes (Must be at least TKeyboardData or greater)
CountThe number of keyboard data packets to copy from the buffer
Returns
ERROR_SUCCESS if completed or another error code on failure

◆ keyboard_flush()

uint32_t STDCALL keyboard_flush ( void )

Flush the contents of the global keyboard buffer.

Returns
ERROR_SUCCESS if completed or another error code on failure

◆ keyboard_device_get()

uint32_t STDCALL keyboard_device_get ( KEYBOARD_DEVICE * keyboard,
uint16_t * keycode )

Get the first key code from the buffer of the specified keyboard.

Parameters
KeyboardThe keyboard device to get from
KeyCodeThe returned key code read from the buffer (eg KEY_CODE_A)
Returns
ERROR_SUCCESS if completed or another error code on failure
Note
Key code is the value translated from the scan code using the current keymap it may not be a character code and it may include non printable characters.

To translate a key code to a character call KeymapGetCharCode()

◆ keyboard_device_read()

uint32_t STDCALL keyboard_device_read ( KEYBOARD_DEVICE * keyboard,
void * buffer,
uint32_t size,
uint32_t * count )

Read keyboard data packets from the buffer of the specified keyboard.

Parameters
KeyboardThe keyboard device to read from
BufferPointer to a buffer to copy the keyboard data packets to
SizeThe size of the buffer in bytes (Must be at least TKeyboardData or greater)
CountThe number of keyboard data packets copied to the buffer
Returns
ERROR_SUCCESS if completed or another error code on failure

◆ keyboard_device_control()

uint32_t STDCALL keyboard_device_control ( KEYBOARD_DEVICE * keyboard,
int request,
size_t argument1,
size_t * argument2 )

Perform a control request on the specified keyboard device.

Parameters
KeyboardThe keyboard device to control
RequestThe request code for the operation (eg KEYBOARD_CONTROL_GET_FLAG)
Argument1The first argument for the operation (Dependent on request code)
Argument2The second argument for the operation (Dependent on request code)
Returns
ERROR_SUCCESS if completed or another error code on failure

◆ keyboard_device_set_state()

uint32_t STDCALL keyboard_device_set_state ( KEYBOARD_DEVICE * keyboard,
uint32_t state )

Set the state of the specified keyboard and send a notification.

Parameters
KeyboardThe keyboard to set the state for
StateThe new state to set and notify
Returns
ERROR_SUCCESS if completed or another error code on failure

◆ keyboard_device_create()

KEYBOARD_DEVICE *STDCALL keyboard_device_create ( void )

Create a new Keyboard device entry.

Returns
Pointer to new Keyboard device entry or nil if keyboard could not be created

◆ keyboard_device_create_ex()

KEYBOARD_DEVICE *STDCALL keyboard_device_create_ex ( uint32_t size)

Create a new Keyboard device entry.

Parameters
SizeSize in bytes to allocate for new keyboard (Including the keyboard device entry)
Returns
Pointer to new Keyboard device entry or nil if keyboard could not be created

◆ keyboard_device_destroy()

uint32_t STDCALL keyboard_device_destroy ( KEYBOARD_DEVICE * keyboard)

Destroy an existing Keyboard device entry.

Parameters
KeyboardThe keyboard device to destroy
Returns
ERROR_SUCCESS if completed or another error code on failure

◆ keyboard_device_register()

uint32_t STDCALL keyboard_device_register ( KEYBOARD_DEVICE * keyboard)

Register a new Keyboard device in the Keyboard table.

Parameters
KeyboardThe keyboard device to register
Returns
ERROR_SUCCESS if completed or another error code on failure

◆ keyboard_device_deregister()

uint32_t STDCALL keyboard_device_deregister ( KEYBOARD_DEVICE * keyboard)

Deregister a Keyboard device from the Keyboard table.

Parameters
KeyboardThe keyboard device to deregister
Returns
ERROR_SUCCESS if completed or another error code on failure

◆ keyboard_device_find()

KEYBOARD_DEVICE *STDCALL keyboard_device_find ( uint32_t keyboardid)

Find a keyboard device by ID in the keyboard table.

Parameters
KeyboardIdThe ID number of the keyboard to find
Returns
Pointer to keyboard device entry or nil if not found

◆ keyboard_device_find_by_name()

KEYBOARD_DEVICE *STDCALL keyboard_device_find_by_name ( const char * name)

Find a keyboard device by name in the keyboard table.

Parameters
NameThe name of the keyboard to find (eg Keyboard0)
Returns
Pointer to keyboard device entry or nil if not found

◆ keyboard_device_find_by_description()

KEYBOARD_DEVICE *STDCALL keyboard_device_find_by_description ( const char * description)

Find a keyboard device by description in the keyboard table.

Parameters
DescriptionThe description of the keyboard to find (eg USB HID Keyboard)
Returns
Pointer to keyboard device entry or nil if not found

◆ keyboard_device_enumerate()

uint32_t STDCALL keyboard_device_enumerate ( keyboard_enumerate_cb callback,
void * data )

Enumerate all keyboard devices in the keyboard table.

Parameters
CallbackThe callback function to call for each keyboard in the table
DataA private data pointer to pass to callback for each keyboard in the table
Returns
ERROR_SUCCESS if completed or another error code on failure

◆ keyboard_device_notification()

uint32_t STDCALL keyboard_device_notification ( KEYBOARD_DEVICE * keyboard,
keyboard_notification_cb callback,
void * data,
uint32_t notification,
uint32_t flags )

Register a notification for keyboard device changes.

Parameters
KeyboardThe keyboard device to notify changes for (Optional, pass nil for all keyboards)
CallbackThe function to call when a notification event occurs
DataA private data pointer to pass to callback when a notification event occurs
NotificationThe events to register for notification of (eg DEVICE_NOTIFICATION_REGISTER)
FlagsThe flags to control the notification (eg NOTIFIER_FLAG_WORKER)

◆ keyboard_get_count()

uint32_t STDCALL keyboard_get_count ( void )

Get the current keyboard count.

Keyboard Helper Functions

◆ keyboard_device_check()

KEYBOARD_DEVICE *STDCALL keyboard_device_check ( KEYBOARD_DEVICE * keyboard)

Check if the supplied Keyboard is in the keyboard table.

◆ keyboard_device_type_to_string()

uint32_t STDCALL keyboard_device_type_to_string ( uint32_t keyboardtype,
char * string,
uint32_t len )

◆ keyboard_device_state_to_string()

uint32_t STDCALL keyboard_device_state_to_string ( uint32_t keyboardstate,
char * string,
uint32_t len )

◆ keyboard_device_state_to_notification()

uint32_t STDCALL keyboard_device_state_to_notification ( uint32_t state)

Convert a Keyboard state value into the notification code for device notifications.

◆ keyboard_remap_ctrl_code()

uint16_t STDCALL keyboard_remap_ctrl_code ( uint16_t keycode,
uint16_t charcode )

Remap Ctrl-<Key> combinations to ASCII control codes.

Note
Caller must check for Left-Ctrl or Right-Ctrl modifiers

◆ keyboard_remap_key_code()

BOOL STDCALL keyboard_remap_key_code ( uint16_t scancode,
uint16_t keycode,
uint8_t * charcode,
uint32_t modifiers )

Remap the SCAN_CODE_* and KEY_CODE_* values to DOS compatible scan codes.

Returns
True if the key was remapped, False if it was not
See also
http://www.freepascal.org/docs-html/rtl/keyboard/kbdscancode.html
Note
See below for a version that uses SCAN_CODE_* values instead of translated KEY_CODE_* values

◆ keyboard_remap_scan_code()

BOOL STDCALL keyboard_remap_scan_code ( uint16_t scancode,
uint16_t keycode,
uint8_t * charcode,
uint32_t modifiers )

Remap the SCAN_CODE_* and KEY_CODE_* values to DOS compatible scan codes.

Returns
True if the key was remapped, False if it was not
See also
http://www.freepascal.org/docs-html/rtl/keyboard/kbdscancode.html
Note
Same as above except using SCAN_CODE_* values instead of translated KEY_CODE_* values

◆ keyboard_insert_data()

uint32_t STDCALL keyboard_insert_data ( KEYBOARD_DEVICE * keyboard,
KEYBOARD_DATA * data,
BOOL signal )

Insert a TKeyboardData entry into the keyboard buffer (Direct or Global).

Parameters
KeyboardThe keyboard device to insert data for
DataThe TKeyboardData entry to insert
SignalIf True then signal that new data is available in the buffer
Returns
ERROR_SUCCESS if completed or another error code on failure
Note
Caller must hold the keyboard lock

Variable Documentation

◆ PACKED

struct _USB_HID_DESCRIPTOR PACKED