Difference between revisions of "Unit Keyboard"

From Ultibo.org
Jump to: navigation, search
 
(5 intermediate revisions by the same user not shown)
Line 9: Line 9:
 
'''Keyboard Devices'''
 
'''Keyboard Devices'''
  
This unit provides both the Keyboard device interface and a generic USB keyboard driver.
+
This unit provides the Keyboard device interface and keyboard API to be used by both drivers and applications.
  
The keyboard unit also provides the STDIN interface for the Run Time Library (RTL).
+
The API includes functions to create, register, locate, read, write, control and configure each connected keyboard device.
  
'''USB Keyboard Devices'''
+
The API supports a global keyboard buffer so multiple devices can feed data into a common buffer as well as a buffer per device to allow each device to be used for a specific purpose. For example an application with two separate displays may choose to have a keyboard device to control each one individually.
 
+
The USB keyboard driver in this unit uses HID Boot Protocol only and has been replaced by the HIDKeyboard unit which provides complete HID Report Protocol support for USB keyboards.
+
+
This driver will be moved to a separate unit and retained for backwards compatibility only.
+
  
 
=== Constants ===
 
=== Constants ===
Line 88: Line 84:
 
<div class="mw-collapsible-content" style="text-align: left; padding-left: 5px;">
 
<div class="mw-collapsible-content" style="text-align: left; padding-left: 5px;">
 
{| class="wikitable" style="font-size: 14px; background: white;"
 
{| class="wikitable" style="font-size: 14px; background: white;"
|-
 
| <code>KEYBOARD_FLAG_NONE = $00000000;</code>
 
| style="width: 50%;"|&nbsp;
 
 
|-
 
|-
 
| <code>KEYBOARD_FLAG_NON_BLOCK = $00000001;</code>
 
| <code>KEYBOARD_FLAG_NON_BLOCK = $00000001;</code>
| &nbsp;
+
| If set device reads are non blocking (Also supported in Flags parameter of KeyboardReadEx)
 
|-
 
|-
 
| <code>KEYBOARD_FLAG_DIRECT_READ = $00000002;</code>
 
| <code>KEYBOARD_FLAG_DIRECT_READ = $00000002;</code>
| &nbsp;
+
| If set device writes keyboard data to its local buffer which must be read using KeyboardDeviceRead
 +
|-
 +
| <code>KEYBOARD_FLAG_PEEK_BUFFER = $00000004;</code>
 +
| Peek at the buffer to see if any data is available, don't remove it (Used only in Flags parameter of KeyboardReadEx)
 
|-
 
|-
 
| <code>KEYBOARD_FLAG_PEEK_BUFFER = $00000004;</code>
 
| <code>KEYBOARD_FLAG_PEEK_BUFFER = $00000004;</code>
Line 298: Line 294:
 
{| class="wikitable" style="font-size: 14px; background: white;"
 
{| class="wikitable" style="font-size: 14px; background: white;"
 
|-
 
|-
| <code>USBKEYBOARD_DRIVER_NAME = 'USB Keyboard Driver (HID boot protocol)';</code>
+
|colspan="2"|Note: The following constants are duplicated with the USBKeyboard unit for backwards compatibility
| Name of USB keyboard driver
+
|-
+
| <code>USBKEYBOARD_KEYBOARD_DESCRIPTION = 'USB HID Keyboard';</code>
+
| Description of USB keyboard device
+
 
|-
 
|-
 
|}
 
|}
Line 640: Line 632:
 
{| class="wikitable" style="font-size: 14px; text-align: left; width: 100%; height: 50px;"
 
{| class="wikitable" style="font-size: 14px; text-align: left; width: 100%; height: 50px;"
 
|-
 
|-
| <code>TKeyboardDeviceControl = function(Keyboard:PKeyboardDevice; Request:Integer; Argument1:LongWord; var Argument2:LongWord):LongWord;</code>
+
| <code>TKeyboardDeviceControl = function(Keyboard:PKeyboardDevice; Request:Integer; Argument1:PtrUInt; var Argument2:PtrUInt):LongWord;</code>
 
| style="width: 40%;"|
 
| style="width: 40%;"|
 
|-
 
|-
Line 852: Line 844:
 
<div class="toccolours mw-collapsible mw-collapsed" style="border: 1; font-family: arial; padding-top: 0px; padding-bottom: 15px;">
 
<div class="toccolours mw-collapsible mw-collapsed" style="border: 1; font-family: arial; padding-top: 0px; padding-bottom: 15px;">
 
<pre style="border: 0; padding-bottom:0px;">procedure KeyboardInit;</pre>
 
<pre style="border: 0; padding-bottom:0px;">procedure KeyboardInit;</pre>
<div style="font-size: 14px; padding-left: 12px;">'''Description:''' Initialize the keyboard unit, device table and USB keyboard driver</div>
+
<div style="font-size: 14px; padding-left: 12px;">'''Description:''' Initialize the keyboard unit and device table</div>
 
<div class="mw-collapsible-content" style="text-align: left; padding-left: 5px;">
 
<div class="mw-collapsible-content" style="text-align: left; padding-left: 5px;">
 
{| class="wikitable" style="font-size: 14px; background: white;"
 
{| class="wikitable" style="font-size: 14px; background: white;"
Line 1,042: Line 1,034:
 
<br />
 
<br />
 
<div class="toccolours mw-collapsible mw-collapsed" style="border: 1; font-family: arial; padding-top: 0px; padding-bottom: 15px;">
 
<div class="toccolours mw-collapsible mw-collapsed" style="border: 1; font-family: arial; padding-top: 0px; padding-bottom: 15px;">
<pre style="border: 0; padding-bottom:0px;">function KeyboardDeviceControl(Keyboard:PKeyboardDevice; Request:Integer; Argument1:LongWord; var Argument2:LongWord):LongWord;</pre>
+
<pre style="border: 0; padding-bottom:0px;">function KeyboardDeviceControl(Keyboard:PKeyboardDevice; Request:Integer; Argument1:PtrUInt; var Argument2:PtrUInt):LongWord;</pre>
 
<div style="font-size: 14px; padding-left: 12px;">'''Description:''' Perform a control request on the specified keyboard device</div>
 
<div style="font-size: 14px; padding-left: 12px;">'''Description:''' Perform a control request on the specified keyboard device</div>
 
<div class="mw-collapsible-content" style="text-align: left; padding-left: 5px;">
 
<div class="mw-collapsible-content" style="text-align: left; padding-left: 5px;">
Line 1,289: Line 1,281:
 
! Note
 
! Note
 
| None documented
 
| None documented
|-
 
|}
 
</div></div>
 
<br />
 
 
'''USB keyboard functions'''
 
 
<div class="toccolours mw-collapsible mw-collapsed" style="border: 1; font-family: arial; padding-top: 0px; padding-bottom: 15px;">
 
<pre style="border: 0; padding-bottom:0px;">function USBKeyboardDeviceRead(Keyboard:PKeyboardDevice; Buffer:Pointer; Size:LongWord; var Count:LongWord):LongWord;</pre>
 
<div style="font-size: 14px; padding-left: 12px;">'''Description:''' Implementation of KeyboardDeviceRead API for USB Keyboard</div>
 
<div class="mw-collapsible-content" style="text-align: left; padding-left: 5px;">
 
{| class="wikitable" style="font-size: 14px; background: white;"
 
|-
 
! Note
 
| Not intended to be called directly by applications, use KeyboardDeviceRead instead.
 
|-
 
|}
 
</div></div>
 
<br />
 
<div class="toccolours mw-collapsible mw-collapsed" style="border: 1; font-family: arial; padding-top: 0px; padding-bottom: 15px;">
 
<pre style="border: 0; padding-bottom:0px;">function USBKeyboardDeviceControl(Keyboard:PKeyboardDevice; Request:Integer; Argument1:LongWord; var Argument2:LongWord):LongWord;</pre>
 
<div style="font-size: 14px; padding-left: 12px;">'''Description:''' Implementation of KeyboardDeviceControl API for USB Keyboard</div>
 
<div class="mw-collapsible-content" style="text-align: left; padding-left: 5px;">
 
{| class="wikitable" style="font-size: 14px; background: white;"
 
|-
 
! Note
 
| Not intended to be called directly by applications, use KeyboardDeviceControl instead.
 
|-
 
|}
 
</div></div>
 
<br />
 
<div class="toccolours mw-collapsible mw-collapsed" style="border: 1; font-family: arial; padding-top: 0px; padding-bottom: 15px;">
 
<pre style="border: 0; padding-bottom:0px;">function USBKeyboardDriverBind(Device:PUSBDevice; Interrface:PUSBInterface):LongWord;</pre>
 
<div style="font-size: 14px; padding-left: 12px;">'''Description:''' Bind the Keyboard driver to a USB device if it is suitable</div>
 
<div class="mw-collapsible-content" style="text-align: left; padding-left: 5px;">
 
{| class="wikitable" style="font-size: 14px; background: white;"
 
|-
 
! Device
 
| The USB device to attempt to bind to
 
|-
 
! Interrface
 
| The USB interface to attempt to bind to (or nil for whole device)
 
|-
 
! Return
 
| USB_STATUS_SUCCESS if completed, USB_STATUS_DEVICE_UNSUPPORTED if unsupported or another error code on failure.
 
|-
 
|}
 
</div></div>
 
<br />
 
<div class="toccolours mw-collapsible mw-collapsed" style="border: 1; font-family: arial; padding-top: 0px; padding-bottom: 15px;">
 
<pre style="border: 0; padding-bottom:0px;">function USBKeyboardDriverUnbind(Device:PUSBDevice; Interrface:PUSBInterface):LongWord;</pre>
 
<div style="font-size: 14px; padding-left: 12px;">'''Description:''' Unbind the Keyboard driver from a USB device</div>
 
<div class="mw-collapsible-content" style="text-align: left; padding-left: 5px;">
 
{| class="wikitable" style="font-size: 14px; background: white;"
 
|-
 
! Device
 
| The USB device to unbind from
 
|-
 
! Interrface
 
| The USB interface to unbind from (or nil for whole device)
 
|-
 
! Return
 
| USB_STATUS_SUCCESS if completed or another error code on failure
 
|-
 
|}
 
</div></div>
 
<br />
 
<div class="toccolours mw-collapsible mw-collapsed" style="border: 1; font-family: arial; padding-top: 0px; padding-bottom: 15px;">
 
<pre style="border: 0; padding-bottom:0px;">procedure USBKeyboardReportWorker(Request:PUSBRequest);</pre>
 
<div style="font-size: 14px; padding-left: 12px;">'''Description:''' Called (by a Worker thread) to process a completed USB request from a USB keyboard IN interrupt endpoint</div>
 
<div class="mw-collapsible-content" style="text-align: left; padding-left: 5px;">
 
{| class="wikitable" style="font-size: 14px; background: white;"
 
|-
 
! Request
 
| The USB request which has completed
 
|-
 
|}
 
</div></div>
 
<br />
 
<div class="toccolours mw-collapsible mw-collapsed" style="border: 1; font-family: arial; padding-top: 0px; padding-bottom: 15px;">
 
<pre style="border: 0; padding-bottom:0px;">procedure USBKeyboardReportComplete(Request:PUSBRequest);</pre>
 
<div style="font-size: 14px; padding-left: 12px;">'''Description:''' Called when a USB request from a USB keyboard IN interrupt endpoint completes</div>
 
<div class="mw-collapsible-content" style="text-align: left; padding-left: 5px;">
 
{| class="wikitable" style="font-size: 14px; background: white;"
 
|-
 
! Request
 
| The USB request which has completed
 
|-
 
! Note
 
| Request is passed to worker thread for processing to prevent blocking the USB completion
 
 
|-
 
|-
 
|}
 
|}
Line 1,387: Line 1,289:
  
 
<div class="toccolours mw-collapsible mw-collapsed" style="border: 1; font-family: arial; padding-top: 0px; padding-bottom: 15px;">
 
<div class="toccolours mw-collapsible mw-collapsed" style="border: 1; font-family: arial; padding-top: 0px; padding-bottom: 15px;">
<pre style="border: 0; padding-bottom:0px;">function KeyboardGetCount:LongWord; inline;</pre>
+
<pre style="border: 0; padding-bottom:0px;">function KeyboardGetCount:LongWord;</pre>
 
<div style="font-size: 14px; padding-left: 12px;">'''Description:''' Get the current keyboard count</div>
 
<div style="font-size: 14px; padding-left: 12px;">'''Description:''' Get the current keyboard count</div>
 
<div class="mw-collapsible-content" style="text-align: left; padding-left: 5px;">
 
<div class="mw-collapsible-content" style="text-align: left; padding-left: 5px;">
Line 1,509: Line 1,411:
 
|-
 
|-
 
! Signal
 
! Signal
| If True then signal that new data is availale in the buffer
+
| If True then signal that new data is available in the buffer
 
|-
 
|-
 
! Return
 
! Return
Line 1,576: Line 1,478:
 
! Note
 
! Note
 
| None documented
 
| None documented
|-
 
|}
 
</div></div>
 
<br />
 
 
'''USB keyboard helper functions'''
 
 
<div class="toccolours mw-collapsible mw-collapsed" style="border: 1; font-family: arial; padding-top: 0px; padding-bottom: 15px;">
 
<pre style="border: 0; padding-bottom:0px;">function USBKeyboardCheckDevice(Device:PUSBDevice):Boolean;</pre>
 
<div style="font-size: 14px; padding-left: 12px;">'''Description:''' Check if the supplied USB device is suitable for detection as a HID Keyboard Device</div>
 
<div class="mw-collapsible-content" style="text-align: left; padding-left: 5px;">
 
{| class="wikitable" style="font-size: 14px; background: white;"
 
|-
 
! Device
 
| The USB device to check
 
|-
 
! Return
 
| True if the device is suitable or False if it is not
 
|-
 
|}
 
</div></div>
 
<br />
 
<div class="toccolours mw-collapsible mw-collapsed" style="border: 1; font-family: arial; padding-top: 0px; padding-bottom: 15px;">
 
<pre style="border: 0; padding-bottom:0px;">function USBKeyboardCheckPressed(Keyboard:PUSBKeyboardDevice; ScanCode:Byte):Boolean;</pre>
 
<div style="font-size: 14px; padding-left: 12px;">'''Description:''' Check if the passed scan code has been pressed (True if not pressed in last report)</div>
 
<div class="mw-collapsible-content" style="text-align: left; padding-left: 5px;">
 
{| class="wikitable" style="font-size: 14px; background: white;"
 
|-
 
! Keyboard
 
| The USB keyboard device to check for
 
|-
 
! ScanCode
 
| The keyboard scan code to check
 
|-
 
! Note
 
| Caller must hold the keyboard lock
 
|-
 
|}
 
</div></div>
 
<br />
 
<div class="toccolours mw-collapsible mw-collapsed" style="border: 1; font-family: arial; padding-top: 0px; padding-bottom: 15px;">
 
<pre style="border: 0; padding-bottom:0px;">function USBKeyboardCheckRepeated(Keyboard:PUSBKeyboardDevice; ScanCode:Byte):Boolean;</pre>
 
<div style="font-size: 14px; padding-left: 12px;">'''Description:''' Check if the passed scan code was the last key pressed and if the repeat delay has expired</div>
 
<div class="mw-collapsible-content" style="text-align: left; padding-left: 5px;">
 
{| class="wikitable" style="font-size: 14px; background: white;"
 
|-
 
! Keyboard
 
| The USB keyboard device to check for
 
|-
 
! ScanCode
 
| The keyboard scan code to check
 
|-
 
! Note
 
| Caller must hold the keyboard lock
 
|-
 
|}
 
</div></div>
 
<br />
 
<div class="toccolours mw-collapsible mw-collapsed" style="border: 1; font-family: arial; padding-top: 0px; padding-bottom: 15px;">
 
<pre style="border: 0; padding-bottom:0px;">function USBKeyboardCheckReleased(Keyboard:PUSBKeyboardDevice; Report:PUSBKeyboardReport; ScanCode:Byte):Boolean;</pre>
 
<div style="font-size: 14px; padding-left: 12px;">'''Description:''' Check if the passed scan code has been released (True if not pressed in current report)</div>
 
<div class="mw-collapsible-content" style="text-align: left; padding-left: 5px;">
 
{| class="wikitable" style="font-size: 14px; background: white;"
 
|-
 
! Keyboard
 
| The USB keyboard device to check for
 
|-
 
! Report
 
| The USB keyboard report to compare against (Current)
 
|-
 
! ScanCode
 
| The keyboard scan code to check
 
|-
 
! Note
 
| Caller must hold the keyboard lock
 
|-
 
|}
 
</div></div>
 
<br />
 
<div class="toccolours mw-collapsible mw-collapsed" style="border: 1; font-family: arial; padding-top: 0px; padding-bottom: 15px;">
 
<pre style="border: 0; padding-bottom:0px;">function USBKeyboardDeviceSetLEDs(Keyboard:PUSBKeyboardDevice; LEDs:Byte):LongWord;</pre>
 
<div style="font-size: 14px; padding-left: 12px;">'''Description:''' Set the state of the LEDs for a USB keyboard device</div>
 
<div class="mw-collapsible-content" style="text-align: left; padding-left: 5px;">
 
{| class="wikitable" style="font-size: 14px; background: white;"
 
|-
 
! Keyboard
 
| The USB keyboard device to set the LEDs for
 
|-
 
! LEDs
 
| The LED state to set (eg KEYBOARD_LED_NUMLOCK)
 
|-
 
! Return
 
| USB_STATUS_SUCCESS if completed or another USB error code on failure
 
|-
 
|}
 
</div></div>
 
<br />
 
<div class="toccolours mw-collapsible mw-collapsed" style="border: 1; font-family: arial; padding-top: 0px; padding-bottom: 15px;">
 
<pre style="border: 0; padding-bottom:0px;">function USBKeyboardDeviceSetIdle(Keyboard:PUSBKeyboardDevice; Duration,ReportId:Byte):LongWord;</pre>
 
<div style="font-size: 14px; padding-left: 12px;">'''Description:''' Set the idle duration (Time between reports when no changes) for a USB keyboard device</div>
 
<div class="mw-collapsible-content" style="text-align: left; padding-left: 5px;">
 
{| class="wikitable" style="font-size: 14px; background: white;"
 
|-
 
! Keyboard
 
| The USB keyboard device to set the idle duration for
 
|-
 
! Duration
 
| The idle duration to set (Milliseconds divided by 4)
 
|-
 
! ReportId
 
| The report Id to set the idle duration for (eg USB_HID_REPORTID_NONE)
 
|-
 
! Return
 
| USB_STATUS_SUCCESS if completed or another USB error code on failure
 
|-
 
|}
 
</div></div>
 
<br />
 
<div class="toccolours mw-collapsible mw-collapsed" style="border: 1; font-family: arial; padding-top: 0px; padding-bottom: 15px;">
 
<pre style="border: 0; padding-bottom:0px;">function USBKeyboardDeviceSetProtocol(Keyboard:PUSBKeyboardDevice; Protocol:Byte):LongWord;</pre>
 
<div style="font-size: 14px; padding-left: 12px;">'''Description:''' Set the report protocol for a USB keyboard device</div>
 
<div class="mw-collapsible-content" style="text-align: left; padding-left: 5px;">
 
{| class="wikitable" style="font-size: 14px; background: white;"
 
|-
 
! Keyboard
 
| The USB keyboard device to set the report protocol for
 
|-
 
! Protocol
 
| The report protocol to set (eg USB_HID_PROTOCOL_BOOT)
 
|-
 
! Return
 
| USB_STATUS_SUCCESS if completed or another USB error code on failure
 
|-
 
|}
 
</div></div>
 
<br />
 
<div class="toccolours mw-collapsible mw-collapsed" style="border: 1; font-family: arial; padding-top: 0px; padding-bottom: 15px;">
 
<pre style="border: 0; padding-bottom:0px;">function USBKeyboardDeviceGetHIDDescriptor(Keyboard:PUSBKeyboardDevice; Descriptor:PUSBHIDDescriptor):LongWord;</pre>
 
<div style="font-size: 14px; padding-left: 12px;">'''Description:''' Get the HID Descriptor for a USB keyboard device</div>
 
<div class="mw-collapsible-content" style="text-align: left; padding-left: 5px;">
 
{| class="wikitable" style="font-size: 14px; background: white;"
 
|-
 
! Keyboard
 
| The USB keyboard device to get the descriptor for
 
|-
 
! Descriptor
 
| Pointer to a USB HID Descriptor structure for the returned data
 
|-
 
! Return
 
| USB_STATUS_SUCCESS if completed or another USB error code on failure
 
|-
 
|}
 
</div></div>
 
<br />
 
<div class="toccolours mw-collapsible mw-collapsed" style="border: 1; font-family: arial; padding-top: 0px; padding-bottom: 15px;">
 
<pre style="border: 0; padding-bottom:0px;">function USBKeyboardDeviceGetReportDescriptor(Keyboard:PUSBKeyboardDevice; Descriptor:Pointer; Size:LongWord):LongWord;</pre>
 
<div style="font-size: 14px; padding-left: 12px;">'''Description:''' Get the Report Descriptor for a USB keyboard device</div>
 
<div class="mw-collapsible-content" style="text-align: left; padding-left: 5px;">
 
{| class="wikitable" style="font-size: 14px; background: white;"
 
|-
 
! Keyboard
 
| The USB keyboard device to get the descriptor for
 
|-
 
! Descriptor
 
| Pointer to a buffer to return the USB Report Descriptor
 
|-
 
! Size
 
| The size in bytes of the buffer pointed to by Descriptor
 
|-
 
! Return
 
| USB_STATUS_SUCCESS if completed or another USB error code on failure
 
 
|-
 
|-
 
|}
 
|}

Latest revision as of 04:48, 10 October 2023

Return to Unit Reference


Description


Ultibo Keyboard Interface unit

Keyboard Devices

This unit provides the Keyboard device interface and keyboard API to be used by both drivers and applications.

The API includes functions to create, register, locate, read, write, control and configure each connected keyboard device.

The API supports a global keyboard buffer so multiple devices can feed data into a common buffer as well as a buffer per device to allow each device to be used for a specific purpose. For example an application with two separate displays may choose to have a keyboard device to control each one individually.

Constants



[Expand]
Keyboard specific constants KEYBOARD_NAME_*


[Expand]
Keyboard device type KEYBOARD_TYPE_*


[Expand]
Keyboard device state KEYBOARD_STATE_*


[Expand]
Keyboard device flag KEYBOARD_FLAG_*


[Expand]
Keyboard device control code KEYBOARD_CONTROL_*


[Expand]
Keyboard device LED KEYBOARD_LED_*


[Expand]
Keyboard buffer size KEYBOARD_BUFFER_*


[Expand]
Keyboard sampling rate KEYBOARD_REPEAT_*


[Expand]
Keyboard data definition KEYBOARD_*


[Expand]
Keyboard logging KEYBOARD_LOG_*


[Expand]
USB keyboard specific constants USBKEYBOARD_*


[Expand]
USB HID interface subclass USB_HID_SUBCLASS_*


[Expand]
USB HID interface protocol USB_HID_BOOT_PROTOCOL_*


[Expand]
USB HID class descriptor USB_HID_DESCRIPTOR_*


[Expand]
USB HID request USB_HID_REQUEST_*


[Expand]
USB HID protocol USB_HID_PROTOCOL_*


[Expand]
USB HID report USB_HID_REPORT_*


[Expand]
USB HID report Ids USB_HID_REPORTID_*


[Expand]
USB HID boot protocol USB_HID_BOOT_LEFT_*, USB_HID_BOOT_RIGHT_*


[Expand]
USB HID boot protocol report data USB_HID_BOOT_REPORT_*


[Expand]
USB HID boot protocol output USB_HID_BOOT_*_LED


[Expand]
USB HID boot protocol output data USB_HID_BOOT_OUTPUT_*


Type definitions



Keyboard data

[Expand]

PKeyboardData = ^TKeyboardData;

TKeyboardData = record

Keyboard buffer

[Expand]

PKeyboardBuffer = ^TKeyboardBuffer;

TKeyboardBuffer = record

Keyboard enumeration callback

TKeyboardEnumerate = function(Keyboard:PKeyboardDevice; Data:Pointer):LongWord;

Keyboard notification callback

TKeyboardNotification = function(Device:PDevice;Data:Pointer;Notification:LongWord):LongWord;

Keyboard device get

TKeyboardDeviceGet = function(Keyboard:PKeyboardDevice; var KeyCode:Word):LongWord;

Keyboard device read

TKeyboardDeviceRead = function(Keyboard:PKeyboardDevice; Buffer:Pointer; Size:LongWord; var Count:LongWord):LongWord;

Keyboard device control

TKeyboardDeviceControl = function(Keyboard:PKeyboardDevice; Request:Integer; Argument1:PtrUInt; var Argument2:PtrUInt):LongWord;

Keyboard device

[Expand]

PKeyboardDevice = ^TKeyboardDevice;

TKeyboardDevice = record

USB HID descriptor

[Expand]

PUSBHIDDescriptor = ^TUSBHIDDescriptor;

TUSBHIDDescriptor = packed record

USB keyboard report

[Expand]

PUSBKeyboardReport = ^TUSBKeyboardReport;

TUSBKeyboardReport = array[0..7] of Byte;

USB keyboard device

[Expand]

PUSBKeyboardDevice = ^TUSBKeyboardDevice;

TUSBKeyboardDevice = record


Public variables



Keyboard logging

KEYBOARD_DEFAULT_LOG_LEVEL:LongWord = KEYBOARD_LOG_LEVEL_DEBUG; Minimum level for Keyboard messages. Only messages with level greater than or equal to this will be printed.
KEYBOARD_LOG_ENABLED:Boolean;


Function declarations



Initialization functions

[Expand]
procedure KeyboardInit;
Description: Initialize the keyboard unit and device table


Keyboard functions

[Expand]
function KeyboardGet(var KeyCode:Word):LongWord;
Description: Get the first key code from the global keyboard buffer


[Expand]
function KeyboardPeek:LongWord;
Description: Peek at the global keyboard buffer to see if any data packets are ready


[Expand]
function KeyboardRead(Buffer:Pointer; Size:LongWord; var Count:LongWord):LongWord; inline;
Description: Read keyboard data packets from the global keyboard buffer


[Expand]
function KeyboardReadEx(Buffer:Pointer; Size,Flags:LongWord; var Count:LongWord):LongWord;
Description: Read keyboard data packets from the global keyboard buffer


[Expand]
function KeyboardPut(ScanCode,KeyCode:Word; Modifiers:LongWord):LongWord;
Description: Put a scan code and key code in the global keyboard buffer


[Expand]
function KeyboardWrite(Buffer:Pointer; Size,Count:LongWord):LongWord;
Description: Write keyboard data packets to the global keyboard buffer


[Expand]
function KeyboardFlush:LongWord;
Description: Flush the contents of the global keyboard buffer


[Expand]
function KeyboardDeviceGet(Keyboard:PKeyboardDevice; var KeyCode:Word):LongWord;
Description: Get the first key code from the buffer of the specified keyboard


[Expand]
function KeyboardDeviceRead(Keyboard:PKeyboardDevice; Buffer:Pointer; Size:LongWord; var Count:LongWord):LongWord;
Description: Read keyboard data packets from the buffer of the specified keyboard


[Expand]
function KeyboardDeviceControl(Keyboard:PKeyboardDevice; Request:Integer; Argument1:PtrUInt; var Argument2:PtrUInt):LongWord;
Description: Perform a control request on the specified keyboard device


[Expand]
function KeyboardDeviceSetState(Keyboard:PKeyboardDevice; State:LongWord):LongWord;
Description: Set the state of the specified keyboard and send a notification


[Expand]
function KeyboardDeviceCreate:PKeyboardDevice;
Description: Create a new Keyboard device entry


[Expand]
function KeyboardDeviceCreateEx(Size:LongWord):PKeyboardDevice;
Description: Create a new Keyboard device entry


[Expand]
function KeyboardDeviceDestroy(Keyboard:PKeyboardDevice):LongWord;
Description: Destroy an existing Keyboard device entry


[Expand]
function KeyboardDeviceRegister(Keyboard:PKeyboardDevice):LongWord;
Description: Register a new Keyboard device in the Keyboard table


[Expand]
function KeyboardDeviceDeregister(Keyboard:PKeyboardDevice):LongWord;
Description: Deregister a Keyboard device from the Keyboard table


[Expand]
function KeyboardDeviceFind(KeyboardId:LongWord):PKeyboardDevice;
Description: Find a keyboard device by ID in the keyboard table


[Expand]
function KeyboardDeviceFindByName(const Name:String):PKeyboardDevice; inline;
Description: Find a keyboard device by name in the keyboard table


[Expand]
function KeyboardDeviceFindByDescription(const Description:String):PKeyboardDevice; inline;
Description: Find a keyboard device by description in the keyboard table


[Expand]
function KeyboardDeviceEnumerate(Callback:TKeyboardEnumerate; Data:Pointer):LongWord;
Description: Enumerate all keyboard devices in the keyboard table


[Expand]
function KeyboardDeviceNotification(Keyboard:PKeyboardDevice; Callback:TKeyboardNotification; Data:Pointer; Notification,Flags:LongWord):LongWord;
Description: Register a notification for keyboard device changes


RTL console functions

[Expand]
function SysConsoleGetKey(var ACh:Char; AUserData:Pointer):Boolean;
Description: Handler for Platform ConsoleGetKey function


[Expand]
function SysConsolePeekKey(var ACh:Char; AUserData:Pointer):Boolean;
Description: Handler for Platform ConsolePeekKey function


[Expand]
function SysConsoleReadChar(var ACh:Char; AUserData:Pointer):Boolean;
Description: Handler for Platform ConsoleReadChar function


[Expand]
function SysConsoleReadWideChar(var ACh:WideChar; AUserData:Pointer):Boolean;
Description: Handler for Platform ConsoleReadWideChar function


Keyboard helper functions

[Expand]
function KeyboardGetCount:LongWord;
Description: Get the current keyboard count


[Expand]
function KeyboardDeviceCheck(Keyboard:PKeyboardDevice):PKeyboardDevice;
Description: Check if the supplied Keyboard is in the keyboard table


[Expand]
function KeyboardDeviceTypeToString(KeyboardType:LongWord):String;
Description: To be documented


[Expand]
function KeyboardDeviceStateToString(KeyboardState:LongWord):String;
Description: To be documented


[Expand]
function KeyboardDeviceStateToNotification(State:LongWord):LongWord;
Description: Convert a Keyboard state value into the notification code for device notifications


[Expand]
function KeyboardRemapCtrlCode(KeyCode,CharCode:Word):Word;
Description: Remap Ctrl-<Key> combinations to ASCII control codes


[Expand]
function KeyboardRemapKeyCode(ScanCode,KeyCode:Word; var CharCode:Byte; Modifiers:LongWord):Boolean;
Description: Remap the SCAN_CODE_* and KEY_CODE_* values to DOS compatible scan codes


[Expand]
function KeyboardRemapScanCode(ScanCode,KeyCode:Word; var CharCode:Byte; Modifiers:LongWord):Boolean;
Description: Remap the SCAN_CODE_* and KEY_CODE_* values to DOS compatible scan codes


[Expand]
function KeyboardInsertData(Keyboard:PKeyboardDevice; Data:PKeyboardData; Signal:Boolean):LongWord;
Description: Insert a TKeyboardData entry into the keyboard buffer (Direct or Global)


[Expand]
procedure KeyboardLog(Level:LongWord; Keyboard:PKeyboardDevice; const AText:String);
Description: To be documented


[Expand]
procedure KeyboardLogInfo(Keyboard:PKeyboardDevice; const AText:String); inline;
Description: To be documented


[Expand]
procedure KeyboardLogWarn(Keyboard:PKeyboardDevice; const AText:String); inline;
Description: To be documented


[Expand]
procedure KeyboardLogError(Keyboard:PKeyboardDevice; const AText:String); inline;
Description: To be documented


[Expand]
procedure KeyboardLogDebug(Keyboard:PKeyboardDevice; const AText:String); inline;
Description: To be documented


Return to Unit Reference