Difference between revisions of "Unit Keyboard"

From Ultibo.org
Jump to: navigation, search
 
(27 intermediate revisions by the same user not shown)
Line 4: Line 4:
 
=== Description ===
 
=== Description ===
 
----
 
----
 +
 +
'''Ultibo Keyboard Interface unit'''
  
 
'''Keyboard Devices'''
 
'''Keyboard Devices'''
  
This unit provides both the Keyboard device interface and the generic USB HID keyboard driver. The keyboard unit also provides the STDIN interface for the Run Time Library (RTL).
+
This unit provides the Keyboard device interface and keyboard API to be used by both drivers and applications.
  
'''USB Keyboard Devices'''
+
The API includes functions to create, register, locate, read, write, control and configure each connected keyboard device.
  
This driver currently uses HID Boot Protocol only and could be redesigned in future to use the HID Report Protocol instead to allow for greater language support etc.
+
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 ===
 
=== Constants ===
Line 29: Line 31:
 
<br />
 
<br />
 
<div class="toccolours mw-collapsible mw-collapsed" style="border: 1; font-family: arial; padding-top: 20px; padding-bottom: 15px;">
 
<div class="toccolours mw-collapsible mw-collapsed" style="border: 1; font-family: arial; padding-top: 20px; padding-bottom: 15px;">
<div style="font-size: 14px; padding-left: 12px;">'''Keyboard device type constants''' <code> KEYBOARD_TYPE_* </code></div>
+
<div style="font-size: 14px; padding-left: 12px;">'''Keyboard device type''' <code> KEYBOARD_TYPE_* </code></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 54: Line 56:
 
<br />
 
<br />
 
<div class="toccolours mw-collapsible mw-collapsed" style="border: 1; font-family: arial; padding-top: 20px; padding-bottom: 15px;">
 
<div class="toccolours mw-collapsible mw-collapsed" style="border: 1; font-family: arial; padding-top: 20px; padding-bottom: 15px;">
<div style="font-size: 14px; padding-left: 12px;">'''Keyboard device state constants''' <code> KEYBOARD_STATE_* </code></div>
+
<div style="font-size: 14px; padding-left: 12px;">'''Keyboard device state''' <code> KEYBOARD_STATE_* </code></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 79: Line 81:
 
<br />
 
<br />
 
<div class="toccolours mw-collapsible mw-collapsed" style="border: 1; font-family: arial; padding-top: 20px; padding-bottom: 15px;">
 
<div class="toccolours mw-collapsible mw-collapsed" style="border: 1; font-family: arial; padding-top: 20px; padding-bottom: 15px;">
<div style="font-size: 14px; padding-left: 12px;">'''Keyboard device flag constants''' <code> KEYBOARD_FLAG_* </code></div>
+
<div style="font-size: 14px; padding-left: 12px;">'''Keyboard device flag''' <code> KEYBOARD_FLAG_* </code></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;"
|-
 
| <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 103: Line 105:
 
<br />
 
<br />
 
<div class="toccolours mw-collapsible mw-collapsed" style="border: 1; font-family: arial; padding-top: 20px; padding-bottom: 15px;">
 
<div class="toccolours mw-collapsible mw-collapsed" style="border: 1; font-family: arial; padding-top: 20px; padding-bottom: 15px;">
<div style="font-size: 14px; padding-left: 12px;">'''Keyboard device control code constants''' <code> KEYBOARD_CONTROL_* </code></div>
+
<div style="font-size: 14px; padding-left: 12px;">'''Keyboard device control code''' <code> KEYBOARD_CONTROL_* </code></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 144: Line 146:
 
<br />  
 
<br />  
 
<div class="toccolours mw-collapsible mw-collapsed" style="border: 1; font-family: arial; padding-top: 20px; padding-bottom: 15px;">
 
<div class="toccolours mw-collapsible mw-collapsed" style="border: 1; font-family: arial; padding-top: 20px; padding-bottom: 15px;">
<div style="font-size: 14px; padding-left: 12px;">'''Keyboard device LED constants''' <code> KEYBOARD_LED_* </code></div>
+
<div style="font-size: 14px; padding-left: 12px;">'''Keyboard device LED''' <code> KEYBOARD_LED_* </code></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 174: Line 176:
 
<br />
 
<br />
 
<div class="toccolours mw-collapsible mw-collapsed" style="border: 1; font-family: arial; padding-top: 20px; padding-bottom: 15px;">
 
<div class="toccolours mw-collapsible mw-collapsed" style="border: 1; font-family: arial; padding-top: 20px; padding-bottom: 15px;">
<div style="font-size: 14px; padding-left: 12px;">'''Keyboard buffer size constants''' <code> KEYBOARD_BUFFER_* </code></div>
+
<div style="font-size: 14px; padding-left: 12px;">'''Keyboard buffer size''' <code> KEYBOARD_BUFFER_* </code></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 185: Line 187:
 
<br />
 
<br />
 
<div class="toccolours mw-collapsible mw-collapsed" style="border: 1; font-family: arial; padding-top: 20px; padding-bottom: 15px;">
 
<div class="toccolours mw-collapsible mw-collapsed" style="border: 1; font-family: arial; padding-top: 20px; padding-bottom: 15px;">
<div style="font-size: 14px; padding-left: 12px;">'''Keyboard sampling rate constants''' <code> KEYBOARD_REPEAT_* </code></div>
+
<div style="font-size: 14px; padding-left: 12px;">'''Keyboard sampling rate''' <code> KEYBOARD_REPEAT_* </code></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;"
 
|-
 
|-
| <code>KEYBOARD_REPEAT_RATE = (40 div 4);</code>
+
| <code>KEYBOARD_REPEAT_RATE = 40;</code>
 
| 40msec -> 25cps
 
| 40msec -> 25cps
 
|-
 
|-
Line 199: Line 201:
 
<br />
 
<br />
 
<div class="toccolours mw-collapsible mw-collapsed" style="border: 1; font-family: arial; padding-top: 20px; padding-bottom: 15px;">
 
<div class="toccolours mw-collapsible mw-collapsed" style="border: 1; font-family: arial; padding-top: 20px; padding-bottom: 15px;">
<div style="font-size: 14px; padding-left: 12px;">'''Keyboard data definition constants''' <code> KEYBOARD_* </code></div>
+
<div style="font-size: 14px; padding-left: 12px;">'''Keyboard data definition''' <code> KEYBOARD_* </code></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 255: Line 257:
 
| The key is being repeated
 
| The key is being repeated
 
|-
 
|-
| <code>KEYBOARD_DEADKEY =  $00010000;</code
+
| <code>KEYBOARD_DEADKEY =  $00010000;</code>
 
| The key is a being handled as a deadkey}
 
| The key is a being handled as a deadkey}
 
|-
 
|-
Line 265: Line 267:
 
<br />
 
<br />
 
<div class="toccolours mw-collapsible mw-collapsed" style="border: 1; font-family: arial; padding-top: 20px; padding-bottom: 15px;">
 
<div class="toccolours mw-collapsible mw-collapsed" style="border: 1; font-family: arial; padding-top: 20px; padding-bottom: 15px;">
<div style="font-size: 14px; padding-left: 12px;">'''Keyboard logging constants''' <code> KEYBOARD_LOG_* </code></div>
+
<div style="font-size: 14px; padding-left: 12px;">'''Keyboard logging''' <code> KEYBOARD_LOG_* </code></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 274: Line 276:
 
| <code>KEYBOARD_LOG_LEVEL_INFO = LOG_LEVEL_INFO;</code>
 
| <code>KEYBOARD_LOG_LEVEL_INFO = LOG_LEVEL_INFO;</code>
 
| Keyboard informational messages, such as a device being attached or detached
 
| Keyboard informational messages, such as a device being attached or detached
 +
|-
 +
| <code>KEYBOARD_LOG_LEVEL_WARN = LOG_LEVEL_WARN;</code>
 +
| Keyboard warning messages
 
|-
 
|-
 
| <code>KEYBOARD_LOG_LEVEL_ERROR = LOG_LEVEL_ERROR;</code>
 
| <code>KEYBOARD_LOG_LEVEL_ERROR = LOG_LEVEL_ERROR;</code>
Line 280: Line 285:
 
| <code>KEYBOARD_LOG_LEVEL_NONE = LOG_LEVEL_NONE;</code>
 
| <code>KEYBOARD_LOG_LEVEL_NONE = LOG_LEVEL_NONE;</code>
 
| No Keyboard messages
 
| No Keyboard messages
 +
|-
 +
|}
 +
</div></div>
 +
<br />
 +
<div class="toccolours mw-collapsible mw-collapsed" style="border: 1; font-family: arial; padding-top: 20px; padding-bottom: 15px;">
 +
<div style="font-size: 14px; padding-left: 12px;">'''USB keyboard specific constants''' <code> USBKEYBOARD_* </code></div>
 +
<div class="mw-collapsible-content" style="text-align: left; padding-left: 5px;">
 +
{| class="wikitable" style="font-size: 14px; background: white;"
 +
|-
 +
|colspan="2"|Note: The following constants are duplicated with the USBKeyboard unit for backwards compatibility
 +
|-
 +
|}
 +
</div></div>
 +
<br />
 +
<div class="toccolours mw-collapsible mw-collapsed" style="border: 1; font-family: arial; padding-top: 20px; padding-bottom: 15px;">
 +
<div style="font-size: 14px; padding-left: 12px;">'''USB HID interface subclass''' <code> USB_HID_SUBCLASS_* </code></div>
 +
<div class="mw-collapsible-content" style="text-align: left; padding-left: 5px;">
 +
{| class="wikitable" style="font-size: 14px; background: white;"
 +
|-
 +
|colspan="2"|See USB HID v1.11 specification
 +
|-
 +
|colspan="2"|&nbsp;
 +
|-
 +
| <code>USB_HID_SUBCLASS_NONE = 0;</code>
 +
| Section 4.2
 +
|-
 +
| <code>USB_HID_SUBCLASS_BOOT = 1;</code>
 +
| Section 4.2
 +
|-
 +
|}
 +
</div></div>
 +
<br />
 +
<div class="toccolours mw-collapsible mw-collapsed" style="border: 1; font-family: arial; padding-top: 20px; padding-bottom: 15px;">
 +
<div style="font-size: 14px; padding-left: 12px;">'''USB HID interface protocol''' <code> USB_HID_BOOT_PROTOCOL_* </code></div>
 +
<div class="mw-collapsible-content" style="text-align: left; padding-left: 5px;">
 +
{| class="wikitable" style="font-size: 14px; background: white;"
 +
|-
 +
|colspan="2"|See USB HID v1.11 specification
 +
|-
 +
|colspan="2"|&nbsp;
 +
|-
 +
| <code>USB_HID_BOOT_PROTOCOL_NONE = 0;</code>
 +
| Section 4.3
 +
|-
 +
| <code>USB_HID_BOOT_PROTOCOL_KEYBOARD = 1;</code>
 +
| Section 4.3
 +
|-
 +
| <code>USB_HID_BOOT_PROTOCOL_MOUSE = 2;</code>
 +
| Section 4.3
 +
|-
 +
|}
 +
</div></div>
 +
<br />
 +
<div class="toccolours mw-collapsible mw-collapsed" style="border: 1; font-family: arial; padding-top: 20px; padding-bottom: 15px;">
 +
<div style="font-size: 14px; padding-left: 12px;">'''USB HID class descriptor''' <code> USB_HID_DESCRIPTOR_* </code></div>
 +
<div class="mw-collapsible-content" style="text-align: left; padding-left: 5px;">
 +
{| class="wikitable" style="font-size: 14px; background: white;"
 +
|-
 +
|colspan="2"|See USB HID v1.11 specification
 +
|-
 +
|colspan="2"|&nbsp;
 +
|-
 +
| <code>USB_HID_DESCRIPTOR_TYPE_HID = $21;</code>
 +
| Section 7.1
 +
|-
 +
| <code>USB_HID_DESCRIPTOR_TYPE_REPORT = $22;</code>
 +
| Section 7.1
 +
|-
 +
| <code>USB_HID_DESCRIPTOR_TYPE_PHYSICAL_DESCRIPTOR = $23;</code>
 +
| Section 7.1
 +
|-
 +
|}
 +
</div></div>
 +
<br />
 +
<div class="toccolours mw-collapsible mw-collapsed" style="border: 1; font-family: arial; padding-top: 20px; padding-bottom: 15px;">
 +
<div style="font-size: 14px; padding-left: 12px;">'''USB HID request''' <code> USB_HID_REQUEST_* </code></div>
 +
<div class="mw-collapsible-content" style="text-align: left; padding-left: 5px;">
 +
{| class="wikitable" style="font-size: 14px; background: white;"
 +
|-
 +
|colspan="2"|See USB HID v1.11 specification
 +
|-
 +
|colspan="2"|&nbsp;
 +
|-
 +
| <code>USB_HID_REQUEST_GET_REPORT = $01;</code>
 +
| Section 7.2
 +
|-
 +
| <code>USB_HID_REQUEST_GET_IDLE = $02;</code>
 +
| Section 7.2
 +
|-
 +
| <code>USB_HID_REQUEST_GET_PROTOCOL = $03;</code>
 +
| Section 7.2
 +
|-
 +
| <code>USB_HID_REQUEST_SET_REPORT = $09;</code>
 +
| Section 7.2
 +
|-
 +
| <code>USB_HID_REQUEST_SET_IDLE = $0A;</code>
 +
| Section 7.2
 +
|-
 +
| <code>USB_HID_REQUEST_SET_PROTOCOL = $0B;</code>
 +
| Section 7.2
 +
|-
 +
|}
 +
</div></div>
 +
<br />
 +
<div class="toccolours mw-collapsible mw-collapsed" style="border: 1; font-family: arial; padding-top: 20px; padding-bottom: 15px;">
 +
<div style="font-size: 14px; padding-left: 12px;">'''USB HID protocol''' <code> USB_HID_PROTOCOL_* </code></div>
 +
<div class="mw-collapsible-content" style="text-align: left; padding-left: 5px;">
 +
{| class="wikitable" style="font-size: 14px; background: white;"
 +
|-
 +
|colspan="2"|See USB HID v1.11 specification
 +
|-
 +
|colspan="2"|&nbsp;
 +
|-
 +
| <code>USB_HID_PROTOCOL_BOOT = 0;</code>
 +
| Section 7.2.5
 +
|-
 +
| <code>USB_HID_PROTOCOL_REPORT = 1;</code>
 +
| Section 7.2.5
 +
|-
 +
|}
 +
</div></div>
 +
<br />
 +
<div class="toccolours mw-collapsible mw-collapsed" style="border: 1; font-family: arial; padding-top: 20px; padding-bottom: 15px;">
 +
<div style="font-size: 14px; padding-left: 12px;">'''USB HID report''' <code> USB_HID_REPORT_* </code></div>
 +
<div class="mw-collapsible-content" style="text-align: left; padding-left: 5px;">
 +
{| class="wikitable" style="font-size: 14px; background: white;"
 +
|-
 +
|colspan="2"|See USB HID v1.11 specification
 +
|-
 +
|colspan="2"|&nbsp;
 +
|-
 +
| <code>USB_HID_REPORT_INPUT = 1;</code>
 +
| Section 7.2.1
 +
|-
 +
| <code>USB_HID_REPORT_OUTPUT = 2;</code>
 +
| Section 7.2.1
 +
|-
 +
| <code>USB_HID_REPORT_FEATURE = 3;</code>
 +
| Section 7.2.1
 +
|-
 +
|}
 +
</div></div>
 +
<br />
 +
<div class="toccolours mw-collapsible mw-collapsed" style="border: 1; font-family: arial; padding-top: 20px; padding-bottom: 15px;">
 +
<div style="font-size: 14px; padding-left: 12px;">'''USB HID report Ids''' <code> USB_HID_REPORTID_* </code></div>
 +
<div class="mw-collapsible-content" style="text-align: left; padding-left: 5px;">
 +
{| class="wikitable" style="font-size: 14px; background: white;"
 +
|-
 +
|colspan="2"|See USB HID v1.11 specification
 +
|-
 +
|colspan="2"|&nbsp;
 +
|-
 +
| <code>USB_HID_REPORTID_NONE = 0;</code>
 +
| Section 7.2.1
 +
|-
 +
|}
 +
</div></div>
 +
<br />
 +
<div class="toccolours mw-collapsible mw-collapsed" style="border: 1; font-family: arial; padding-top: 20px; padding-bottom: 15px;">
 +
<div style="font-size: 14px; padding-left: 12px;">'''USB HID boot protocol''' <code> USB_HID_BOOT_LEFT_*, USB_HID_BOOT_RIGHT_*  </code></div>
 +
<div class="mw-collapsible-content" style="text-align: left; padding-left: 5px;">
 +
{| class="wikitable" style="font-size: 14px; background: white;"
 +
|-
 +
| <code>USB_HID_BOOT_LEFT_CTRL = (1 shl 0);</code>
 +
| style="width: 50%;"|&nbsp;
 +
|-
 +
| <code>USB_HID_BOOT_LEFT_SHIFT = (1 shl 1);</code>
 +
| &nbsp;
 +
|-
 +
| <code>USB_HID_BOOT_LEFT_ALT = (1 shl 2);</code>
 +
| &nbsp;
 +
|-
 +
| <code>USB_HID_BOOT_LEFT_GUI = (1 shl 3);</code>
 +
| &nbsp;
 +
|-
 +
| <code>USB_HID_BOOT_RIGHT_CTRL = (1 shl 4);</code>
 +
| &nbsp;
 +
|-
 +
| <code>USB_HID_BOOT_RIGHT_SHIFT = (1 shl 5);</code>
 +
| &nbsp;
 +
|-
 +
| <code>USB_HID_BOOT_RIGHT_ALT = (1 shl 6);</code>
 +
| &nbsp;
 +
|-
 +
| <code>USB_HID_BOOT_RIGHT_GUI = (1 shl 7);</code>
 +
| &nbsp;
 +
|-
 +
|}
 +
</div></div>
 +
<br />
 +
<div class="toccolours mw-collapsible mw-collapsed" style="border: 1; font-family: arial; padding-top: 20px; padding-bottom: 15px;">
 +
<div style="font-size: 14px; padding-left: 12px;">'''USB HID boot protocol report data''' <code> USB_HID_BOOT_REPORT_* </code></div>
 +
<div class="mw-collapsible-content" style="text-align: left; padding-left: 5px;">
 +
{| class="wikitable" style="font-size: 14px; background: white;"
 +
|-
 +
| <code>USB_HID_BOOT_REPORT_SIZE = 8;</code>
 +
| Appendix B of HID Device Class Definition 1.11
 +
|-
 +
|}
 +
</div></div>
 +
<br />
 +
<div class="toccolours mw-collapsible mw-collapsed" style="border: 1; font-family: arial; padding-top: 20px; padding-bottom: 15px;">
 +
<div style="font-size: 14px; padding-left: 12px;">'''USB HID boot protocol output''' <code> USB_HID_BOOT_*_LED </code></div>
 +
<div class="mw-collapsible-content" style="text-align: left; padding-left: 5px;">
 +
{| class="wikitable" style="font-size: 14px; background: white;"
 +
|-
 +
| <code>USB_HID_BOOT_NUMLOCK_LED = (1 shl 0);</code>
 +
| style="width: 50%;"|&nbsp;
 +
|-
 +
| <code>USB_HID_BOOT_CAPSLOCK_LED = (1 shl 1);</code>
 +
| &nbsp;
 +
|-
 +
| <code>USB_HID_BOOT_SCROLLLOCK_LED = (1 shl 2);</code>
 +
| &nbsp;
 +
|-
 +
| <code>USB_HID_BOOT_COMPOSE_LED = (1 shl 3);</code>
 +
| &nbsp;
 +
|-
 +
| <code>USB_HID_BOOT_KANA_LED = (1 shl 4);</code>
 +
| &nbsp;
 +
|-
 +
|colspan="2"|&nbsp;
 +
|-
 +
| <code>USB_HID_BOOT_LEDMASK = USB_HID_BOOT_NUMLOCK_LED or USB_HID_BOOT_CAPSLOCK_LED or USB_HID_BOOT_SCROLLLOCK_LED or USB_HID_BOOT_COMPOSE_LED or USB_HID_BOOT_KANA_LED;</code>
 +
| &nbsp;
 +
|-
 +
|}
 +
</div></div>
 +
<br />
 +
<div class="toccolours mw-collapsible mw-collapsed" style="border: 1; font-family: arial; padding-top: 20px; padding-bottom: 15px;">
 +
<div style="font-size: 14px; padding-left: 12px;">'''USB HID boot protocol output data''' <code> USB_HID_BOOT_OUTPUT_* </code></div>
 +
<div class="mw-collapsible-content" style="text-align: left; padding-left: 5px;">
 +
{| class="wikitable" style="font-size: 14px; background: white;"
 +
|-
 +
| <code>USB_HID_BOOT_OUTPUT_SIZE = 1;</code>
 +
| Appendix B of HID Device Class Definition 1.11
 +
|-
 +
|colspan="2"|&nbsp;
 +
|-
 +
| <code>USB_HID_BOOT_USAGE_NUMLOCK = SCAN_CODE_NUMLOCK;</code>
 +
| 83
 +
|-
 +
| <code>USB_HID_BOOT_USAGE_CAPSLOCK = SCAN_CODE_CAPSLOCK;</code>
 +
| 57
 +
|-
 +
| <code>USB_HID_BOOT_USAGE_SCROLLLOCK = SCAN_CODE_SCROLLLOCK;</code>
 +
| 71
 
|-
 
|-
 
|}
 
|}
Line 288: Line 540:
 
----
 
----
  
''To be documented''
+
 
 +
'''Keyboard data'''
 +
 
 +
<div class="toccolours mw-collapsible mw-collapsed" style="border: 1; font-family: arial;">
 +
<code>PKeyboardData = ^TKeyboardData;</code>
 +
 
 +
<code>TKeyboardData = record</code>
 +
<div class="mw-collapsible-content" style="text-align: left; padding-left: 5px;">
 +
{| class="wikitable" style="font-size: 14px; background: white;"
 +
|-
 +
| <code>Modifiers:LongWord;</code>
 +
| Keyboard modifier flags for Shift, Alt, Control etc (eg KEYBOARD_LEFT_CTRL)
 +
|-
 +
| <code>ScanCode:Word;</code>
 +
| Untranslated scan code value from keyboard (See SCAN_CODE_* constants)
 +
|-
 +
| <code>KeyCode:Word;</code>
 +
| Translated key code value from keyboard (See KEY_CODE_* constants)
 +
|-
 +
| <code>CharCode:Char;</code>
 +
| ANSI character representing the translated key code
 +
|-
 +
| <code>CharUnicode:WideChar;</code>
 +
| Unicode character representing the translated key code
 +
|-
 +
|}
 +
</div></div>
 +
 
 +
'''Keyboard buffer'''
 +
 +
<div class="toccolours mw-collapsible mw-collapsed" style="border: 1; font-family: arial;">
 +
<code>PKeyboardBuffer = ^TKeyboardBuffer;</code>
 +
 
 +
<code>TKeyboardBuffer = record</code>
 +
<div class="mw-collapsible-content" style="text-align: left; padding-left: 5px;">
 +
{| class="wikitable" style="font-size: 14px; background: white;"
 +
|-
 +
| <code>Wait:TSemaphoreHandle;</code>
 +
| Data ready semaphore
 +
|-
 +
| <code>Start:LongWord;</code>
 +
| Index of first buffer ready
 +
|-
 +
| <code>Count:LongWord;</code>
 +
| Number of messages ready in buffer
 +
|-
 +
| <code>Buffer:array[0..(KEYBOARD_BUFFER_SIZE - 1)] of TKeyboardData;</code>
 +
| &nbsp;
 +
|-
 +
|}
 +
</div></div>
 +
 
 +
'''Keyboard enumeration callback'''
 +
 
 +
{| class="wikitable" style="font-size: 14px; text-align: left; width: 100%; height: 50px;"
 +
|-
 +
| <code>TKeyboardEnumerate = function(Keyboard:PKeyboardDevice; Data:Pointer):LongWord;</code>
 +
| style="width: 40%;"|
 +
|-
 +
|}
 +
 
 +
'''Keyboard notification callback'''
 +
 
 +
{| class="wikitable" style="font-size: 14px; text-align: left; width: 100%; height: 50px;"
 +
|-
 +
| <code>TKeyboardNotification = function(Device:PDevice;Data:Pointer;Notification:LongWord):LongWord;</code>
 +
| style="width: 40%;"|
 +
|-
 +
|}
 +
 
 +
'''Keyboard device get'''
 +
 
 +
{| class="wikitable" style="font-size: 14px; text-align: left; width: 100%; height: 50px;"
 +
|-
 +
| <code>TKeyboardDeviceGet = function(Keyboard:PKeyboardDevice; var KeyCode:Word):LongWord;</code>
 +
| style="width: 40%;"|
 +
|-
 +
|}
 +
 
 +
'''Keyboard device read'''
 +
 
 +
{| class="wikitable" style="font-size: 14px; text-align: left; width: 100%; height: 50px;"
 +
|-
 +
| <code>TKeyboardDeviceRead = function(Keyboard:PKeyboardDevice; Buffer:Pointer; Size:LongWord; var Count:LongWord):LongWord;</code>
 +
| style="width: 40%;"|
 +
|-
 +
|}
 +
 
 +
'''Keyboard device control'''
 +
 
 +
{| class="wikitable" style="font-size: 14px; text-align: left; width: 100%; height: 50px;"
 +
|-
 +
| <code>TKeyboardDeviceControl = function(Keyboard:PKeyboardDevice; Request:Integer; Argument1:PtrUInt; var Argument2:PtrUInt):LongWord;</code>
 +
| style="width: 40%;"|
 +
|-
 +
|}
 +
 
 +
'''Keyboard device'''
 +
 
 +
<div class="toccolours mw-collapsible mw-collapsed" style="border: 1; font-family: arial;">
 +
<code>PKeyboardDevice = ^TKeyboardDevice;</code>
 +
 
 +
<code>TKeyboardDevice = record</code>
 +
<div class="mw-collapsible-content" style="text-align: left; padding-left: 5px;">
 +
{| class="wikitable" style="font-size: 14px; background: white;"
 +
|-
 +
|colspan="2"|''Device Properties''
 +
|-
 +
| <code>Device:TDevice;</code>
 +
| The Device entry for this Keyboard
 +
|-
 +
|colspan="2"|''Keyboard Properties''
 +
|-
 +
| <code>KeyboardId:LongWord;</code>
 +
| Unique Id of this Keyboard in the Keyboard table
 +
|-
 +
| <code>KeyboardState:LongWord;</code>
 +
| Keyboard state (eg KEYBOARD_STATE_ATTACHED)
 +
|-
 +
| <code>KeyboardLEDs:LongWord;</code>
 +
| Keyboard LEDs (eg KEYBOARD_LED_NUMLOCK)
 +
|-
 +
| <code>KeyboardRate:LongWord;</code>
 +
| Keyboard repeat rate (Milliseconds)
 +
|-
 +
| <code>KeyboardDelay:LongWord;</code>
 +
| Keyboard repeat delay (Number of KeyboardRate intervals before first repeat)
 +
|-
 +
| <code>DeviceGet:TKeyboardDeviceGet;</code>
 +
| A Device specific DeviceGet method implementing a standard Keyboard device interface (Or nil if the default method is suitable)
 +
|-
 +
| <code>DeviceRead:TKeyboardDeviceRead;</code>
 +
| A Device specific DeviceRead method implementing a standard Keyboard device interface (Or nil if the default method is suitable)
 +
|-
 +
| <code>DeviceControl:TKeyboardDeviceControl;</code>
 +
| A Device specific DeviceControl method implementing a standard Keyboard device interface (Or nil if the default method is suitable)
 +
|-
 +
|colspan="2"|''Driver Properties''
 +
|-
 +
| <code>Lock:TMutexHandle;</code>
 +
| Keyboard lock
 +
|-
 +
| <code>Code:Word;</code>
 +
| Scan code of current deadkey (If Applicable)
 +
|-
 +
| <code>Index:Word;</code>
 +
| Index state for current deadkey (If Applicable)
 +
|-
 +
| <code>Modifiers:LongWord;</code>
 +
| Modifier state for current deadkey (If Applicable)
 +
|-
 +
| <code>Buffer:TKeyboardBuffer;</code>
 +
| Keyboard input buffer
 +
|-
 +
|colspan="2"|''Statistics Properties''
 +
|-
 +
| <code>ReceiveCount:LongWord;</code>
 +
| &nbsp;
 +
|-
 +
| <code>ReceiveErrors:LongWord;</code>
 +
| &nbsp;
 +
|-
 +
| <code>BufferOverruns:LongWord;</code>
 +
| &nbsp;
 +
|-
 +
|colspan="2"|''Internal Properties''
 +
|-
 +
| <code>Prev:PKeyboardDevice;</code>
 +
| Previous entry in Keyboard table
 +
|-
 +
| <code>Next:PKeyboardDevice;</code>
 +
| Next entry in Keyboard table
 +
|-
 +
|}
 +
</div></div>
 +
 
 +
'''USB HID descriptor'''
 +
 
 +
<div class="toccolours mw-collapsible mw-collapsed" style="border: 1; font-family: arial;">
 +
<code>PUSBHIDDescriptor = ^TUSBHIDDescriptor;</code>
 +
 
 +
<code>TUSBHIDDescriptor = packed record</code>
 +
<div class="mw-collapsible-content" style="text-align: left; padding-left: 5px;">
 +
{| class="wikitable" style="font-size: 14px; background: white;"
 +
|-
 +
| <code>bLength:Byte;</code>
 +
| style="width: 50%;"|&nbsp;
 +
|-
 +
| <code>bDescriptorType:Byte;</code>
 +
| &nbsp;
 +
|-
 +
| <code>bcdHID:Word;</code>
 +
| &nbsp;
 +
|-
 +
| <code>bCountryCode:Byte;</code>
 +
| &nbsp;
 +
|-
 +
| <code>bNumDescriptors:Byte;</code>
 +
| &nbsp;
 +
|-
 +
| <code>bHIDDescriptorType:Byte;</code>
 +
| &nbsp;
 +
|-
 +
| <code>wHIDDescriptorLength:Word;</code>
 +
| &nbsp;
 +
|-
 +
|colspan="2"|''Note: Up to two optional bHIDDescriptorType/wHIDDescriptorLength pairs after the Report descriptor details''
 +
|-
 +
|}
 +
</div></div>
 +
 
 +
'''USB keyboard report'''
 +
 
 +
<div class="toccolours mw-collapsible mw-collapsed" style="border: 1; font-family: arial;">
 +
<code>PUSBKeyboardReport = ^TUSBKeyboardReport;</code>
 +
 
 +
<code>TUSBKeyboardReport = array[0..7] of Byte;</code>
 +
<div class="mw-collapsible-content" style="text-align: left; padding-left: 5px;">
 +
{| class="wikitable" style="font-size: 14px; background: white;"
 +
|-
 +
| &nbsp;
 +
| style="width: 50%;"|&nbsp;
 +
|-
 +
|}
 +
</div></div>
 +
 
 +
''' USB keyboard device'''
 +
 +
<div class="toccolours mw-collapsible mw-collapsed" style="border: 1; font-family: arial;">
 +
<code>PUSBKeyboardDevice = ^TUSBKeyboardDevice;</code>
 +
 
 +
<code>TUSBKeyboardDevice = record</code>
 +
<div class="mw-collapsible-content" style="text-align: left; padding-left: 5px;">
 +
{| class="wikitable" style="font-size: 14px; background: white;"
 +
|-
 +
|colspan="2"|''Keyboard Properties''
 +
|-
 +
| <code>Keyboard:TKeyboardDevice;</code>
 +
| &nbsp;
 +
|-
 +
|colspan="2"|''USB Properties''
 +
|-
 +
| <code>HIDInterface:PUSBInterface;</code>
 +
| USB HID Keyboard Interface
 +
|-
 +
| <code>ReportRequest:PUSBRequest;</code>
 +
| USB request for keyboard report data
 +
|-
 +
| <code>ReportEndpoint:PUSBEndpointDescriptor;</code>
 +
| USB Keyboard Interrupt IN Endpoint
 +
|-
 +
| <code>HIDDescriptor:PUSBHIDDescriptor;</code>
 +
| USB HID Descriptor for keyboard
 +
|-
 +
| <code>ReportDescriptor:Pointer;</code>
 +
| USB HID Report Descriptor for keyboard
 +
|-
 +
| <code>LastCode:Word;</code>
 +
| The scan code of the last key pressed
 +
|-
 +
| <code>LastCount:LongWord;</code>
 +
| The repeat count of the last key pressed
 +
|-
 +
| <code>LastReport:TUSBKeyboardReport;</code>
 +
| The last keyboard report received
 +
|-
 +
| <code>PendingCount:LongWord;</code>
 +
| Number of USB requests pending for this keyboard
 +
|-
 +
| <code>WaiterThread:TThreadId;</code>
 +
| Thread waiting for pending requests to complete (for keyboard detachment)
 +
|-
 +
|}
 +
</div></div> 
 +
<br />
  
 
=== Public variables ===
 
=== Public variables ===
 
----
 
----
  
''To be documented''
+
 
 +
'''Keyboard logging'''
 +
 
 +
{| class="wikitable" style="font-size: 14px; text-align: left; width: 100%; height: 50px;"
 +
|-
 +
| <code>KEYBOARD_DEFAULT_LOG_LEVEL:LongWord = KEYBOARD_LOG_LEVEL_DEBUG;</code>
 +
| style="width: 40%;"|Minimum level for Keyboard messages. Only messages with level greater than or equal to this will be printed.
 +
|-
 +
|}
 +
{| class="wikitable" style="font-size: 14px; text-align: left; width: 100%; height: 50px;"
 +
|-
 +
| <code>KEYBOARD_LOG_ENABLED:Boolean;</code>
 +
| style="width: 40%;"|
 +
|-
 +
|}
 +
<br />
  
 
=== Function declarations ===
 
=== Function declarations ===
Line 303: 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;"
 
|-
 
|-
! '''Note'''
+
! Note
 
| Called only during system startup
 
| Called only during system startup
 
|-
 
|-
Line 322: Line 863:
 
{| class="wikitable" style="font-size: 14px; background: white;"
 
{| class="wikitable" style="font-size: 14px; background: white;"
 
|-
 
|-
! '''KeyCode'''
+
! KeyCode
 
| The returned key code read from the buffer (eg KEY_CODE_A)
 
| The returned key code read from the buffer (eg KEY_CODE_A)
 
|-
 
|-
! '''Return'''
+
! Return
 
| ERROR_SUCCESS if completed or another error code on failure
 
| ERROR_SUCCESS if completed or another error code on failure
 
|-
 
|-
! '''Note'''
+
! 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()
+
| 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()
 
|-
 
|-
 
|}
 
|}
Line 340: Line 882:
 
{| class="wikitable" style="font-size: 14px; background: white;"
 
{| class="wikitable" style="font-size: 14px; background: white;"
 
|-
 
|-
! '''Return'''
+
! Return
| ERROR_SUCCESS if packets are ready, ERROR_NO_MORE_ITEMS if not or another error code on failure
+
| ERROR_SUCCESS if packets are ready, ERROR_NO_MORE_ITEMS if not or another error code on failure.
 
|-
 
|-
 
|}
 
|}
Line 352: Line 894:
 
{| class="wikitable" style="font-size: 14px; background: white;"
 
{| class="wikitable" style="font-size: 14px; background: white;"
 
|-
 
|-
! '''Buffer'''
+
! Buffer
 
| Pointer to a buffer to copy the keyboard data packets to
 
| Pointer to a buffer to copy the keyboard data packets to
 
|-
 
|-
! '''Size'''
+
! Size
 
| The size of the buffer in bytes (Must be at least TKeyboardData or greater)
 
| The size of the buffer in bytes (Must be at least TKeyboardData or greater)
 
|-
 
|-
! '''Count'''
+
! Count
 
| The number of keyboard data packets copied to the buffer
 
| The number of keyboard data packets copied to the buffer
 
|-
 
|-
! '''Return'''
+
! Return
 
| ERROR_SUCCESS if completed or another error code on failure
 
| ERROR_SUCCESS if completed or another error code on failure
 
|-
 
|-
Line 373: Line 915:
 
{| class="wikitable" style="font-size: 14px; background: white;"
 
{| class="wikitable" style="font-size: 14px; background: white;"
 
|-
 
|-
! '''Buffer'''
+
! Buffer
 
| Pointer to a buffer to copy the keyboard data packets to
 
| Pointer to a buffer to copy the keyboard data packets to
 
|-
 
|-
! '''Size'''
+
! Size
 
| TThe size of the buffer in bytes (Must be at least TKeyboardData or greater)
 
| TThe size of the buffer in bytes (Must be at least TKeyboardData or greater)
 
|-
 
|-
! '''Flags'''
+
! Flags
 
| The flags to use for the read (eg KEYBOARD_FLAG_NON_BLOCK)
 
| The flags to use for the read (eg KEYBOARD_FLAG_NON_BLOCK)
 
|-
 
|-
! '''Count'''
+
! Count
 
| The number of keyboard data packets copied to the buffer
 
| The number of keyboard data packets copied to the buffer
 
|-
 
|-
! '''Return'''
+
! Return
 
| ERROR_SUCCESS if completed or another error code on failure
 
| ERROR_SUCCESS if completed or another error code on failure
 
|-
 
|-
Line 397: Line 939:
 
{| class="wikitable" style="font-size: 14px; background: white;"
 
{| class="wikitable" style="font-size: 14px; background: white;"
 
|-
 
|-
! '''ScanCode'''
+
! ScanCode
 
| The scan code to write to the buffer (eg SCAN_CODE_A)
 
| The scan code to write to the buffer (eg SCAN_CODE_A)
 
|-
 
|-
! '''KeyCode'''
+
! KeyCode
 
| The key code to write to the buffer (eg KEY_CODE_A)
 
| The key code to write to the buffer (eg KEY_CODE_A)
 
|-
 
|-
! '''Modifiers'''
+
! Modifiers
 
| The modifier keys to write to the buffer (eg KEYBOARD_LEFT_CTRL)
 
| The modifier keys to write to the buffer (eg KEYBOARD_LEFT_CTRL)
 
|-
 
|-
! '''Return'''
+
! Return
 
| ERROR_SUCCESS if completed or another error code on failure
 
| ERROR_SUCCESS if completed or another error code on failure
 
|-
 
|-
Line 418: Line 960:
 
{| class="wikitable" style="font-size: 14px; background: white;"
 
{| class="wikitable" style="font-size: 14px; background: white;"
 
|-
 
|-
! '''Buffer'''
+
! Buffer
 
| Pointer to a buffer to copy the keyboard data packets from
 
| Pointer to a buffer to copy the keyboard data packets from
 
|-
 
|-
! '''Size'''
+
! Size
 
| The size of the buffer in bytes (Must be at least TKeyboardData or greater)
 
| The size of the buffer in bytes (Must be at least TKeyboardData or greater)
 
|-
 
|-
! '''Count'''
+
! Count
 
| The number of keyboard data packets to copy from the buffer
 
| The number of keyboard data packets to copy from the buffer
 
|-
 
|-
! '''Return'''
+
! Return
 
| ERROR_SUCCESS if completed or another error code on failure
 
| ERROR_SUCCESS if completed or another error code on failure
 
|-
 
|-
Line 439: Line 981:
 
{| class="wikitable" style="font-size: 14px; background: white;"
 
{| class="wikitable" style="font-size: 14px; background: white;"
 
|-
 
|-
! '''Return'''
+
! Return
 
| ERROR_SUCCESS if completed or another error code on failure
 
| ERROR_SUCCESS if completed or another error code on failure
 
|-
 
|-
Line 451: Line 993:
 
{| class="wikitable" style="font-size: 14px; background: white;"
 
{| class="wikitable" style="font-size: 14px; background: white;"
 
|-
 
|-
! '''Keyboard'''
+
! Keyboard
 
| The keyboard device to get from
 
| The keyboard device to get from
 
|-
 
|-
! '''Keycode'''
+
! Keycode
 
| The returned key code read from the buffer (eg KEY_CODE_A)
 
| The returned key code read from the buffer (eg KEY_CODE_A)
 
|-
 
|-
! '''Return'''
+
! Return
 
| ERROR_SUCCESS if completed or another error code on failure
 
| ERROR_SUCCESS if completed or another error code on failure
 
|-
 
|-
! '''Note'''
+
! 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()
+
| 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()
 
|-
 
|-
 
|}
 
|}
Line 472: Line 1,015:
 
{| class="wikitable" style="font-size: 14px; background: white;"
 
{| class="wikitable" style="font-size: 14px; background: white;"
 
|-
 
|-
! '''Keyboard'''
+
! Keyboard
 
| The keyboard device to read from
 
| The keyboard device to read from
 
|-
 
|-
! '''Buffer'''
+
! Buffer
 
| Pointer to a buffer to copy the keyboard data packets to
 
| Pointer to a buffer to copy the keyboard data packets to
 
|-
 
|-
! '''Size'''
+
! Size
 
| The size of the buffer in bytes (Must be at least TKeyboardData or greater)
 
| The size of the buffer in bytes (Must be at least TKeyboardData or greater)
 
|-
 
|-
! '''Count'''
+
! Count
 
| The number of keyboard data packets copied to the buffer
 
| The number of keyboard data packets copied to the buffer
 
|-
 
|-
! '''Return'''
+
! Return
 
| ERROR_SUCCESS if completed or another error code on failure
 
| ERROR_SUCCESS if completed or another error code on failure
 
|-
 
|-
Line 491: 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;">
 
{| class="wikitable" style="font-size: 14px; background: white;"
 
{| class="wikitable" style="font-size: 14px; background: white;"
 
|-
 
|-
! '''Keyboard'''
+
! Keyboard
 
| The keyboard device to control
 
| The keyboard device to control
 
|-
 
|-
! '''Request'''
+
! Request
 
| The request code for the operation (eg KEYBOARD_CONTROL_GET_FLAG)
 
| The request code for the operation (eg KEYBOARD_CONTROL_GET_FLAG)
 
|-
 
|-
! '''Argument1'''
+
! Argument1
 
| The first argument for the operation (Dependent on request code)
 
| The first argument for the operation (Dependent on request code)
 
|-
 
|-
! '''Argument2'''
+
! Argument2
 
| The second argument for the operation (Dependent on request code)
 
| The second argument for the operation (Dependent on request code)
 
|-
 
|-
! '''Return'''
+
! Return
 
| ERROR_SUCCESS if completed or another error code on failure
 
| ERROR_SUCCESS if completed or another error code on failure
 
|-
 
|-
Line 520: Line 1,063:
 
{| class="wikitable" style="font-size: 14px; background: white;"
 
{| class="wikitable" style="font-size: 14px; background: white;"
 
|-
 
|-
! '''Keyboard'''
+
! Keyboard
 
| The keyboard to set the state for
 
| The keyboard to set the state for
 
|-
 
|-
! '''State'''
+
! State
 
| The new state to set and notify
 
| The new state to set and notify
 
|-
 
|-
! '''Return'''
+
! Return
 
| ERROR_SUCCESS if completed or another error code on failure
 
| ERROR_SUCCESS if completed or another error code on failure
 
|-
 
|-
Line 538: Line 1,081:
 
{| class="wikitable" style="font-size: 14px; background: white;"
 
{| class="wikitable" style="font-size: 14px; background: white;"
 
|-
 
|-
! '''Return'''
+
! Return
 
| Pointer to new Keyboard device entry or nil if keyboard could not be created
 
| Pointer to new Keyboard device entry or nil if keyboard could not be created
 
|-
 
|-
Line 550: Line 1,093:
 
{| class="wikitable" style="font-size: 14px; background: white;"
 
{| class="wikitable" style="font-size: 14px; background: white;"
 
|-
 
|-
! '''Size'''
+
! Size
 
| Size in bytes to allocate for new keyboard (Including the keyboard device entry)
 
| Size in bytes to allocate for new keyboard (Including the keyboard device entry)
 
|-
 
|-
! '''Return'''
+
! Return
 
| Pointer to new Keyboard device entry or nil if keyboard could not be created
 
| Pointer to new Keyboard device entry or nil if keyboard could not be created
 
|-
 
|-
Line 565: Line 1,108:
 
{| class="wikitable" style="font-size: 14px; background: white;"
 
{| class="wikitable" style="font-size: 14px; background: white;"
 
|-
 
|-
! '''Keyboard'''
+
! Keyboard
 
| The keyboard device to destroy
 
| The keyboard device to destroy
 
|-
 
|-
! '''Return'''
+
! Return
 
| ERROR_SUCCESS if completed or another error code on failure
 
| ERROR_SUCCESS if completed or another error code on failure
 
|-
 
|-
Line 580: Line 1,123:
 
{| class="wikitable" style="font-size: 14px; background: white;"
 
{| class="wikitable" style="font-size: 14px; background: white;"
 
|-
 
|-
! '''Keyboard'''
+
! Keyboard
 
| The keyboard device to register
 
| The keyboard device to register
 
|-
 
|-
! '''Return'''
+
! Return
 
| ERROR_SUCCESS if completed or another error code on failure
 
| ERROR_SUCCESS if completed or another error code on failure
 
|-
 
|-
Line 595: Line 1,138:
 
{| class="wikitable" style="font-size: 14px; background: white;"
 
{| class="wikitable" style="font-size: 14px; background: white;"
 
|-
 
|-
! '''Keyboard'''
+
! Keyboard
 
| The keyboard device to deregister
 
| The keyboard device to deregister
 
|-
 
|-
! '''Return'''
+
! Return
 
| ERROR_SUCCESS if completed or another error code on failure
 
| ERROR_SUCCESS if completed or another error code on failure
 
|-
 
|-
Line 610: Line 1,153:
 
{| class="wikitable" style="font-size: 14px; background: white;"
 
{| class="wikitable" style="font-size: 14px; background: white;"
 
|-
 
|-
! '''KeyboardId'''
+
! KeyboardId
 
| The ID number of the keyboard to find
 
| The ID number of the keyboard to find
 
|-
 
|-
! '''Return'''
+
! Return
 
| Pointer to keyboard device entry or nil if not found
 
| Pointer to keyboard device entry or nil if not found
 
|-
 
|-
Line 625: Line 1,168:
 
{| class="wikitable" style="font-size: 14px; background: white;"
 
{| class="wikitable" style="font-size: 14px; background: white;"
 
|-
 
|-
! '''Name'''
+
! Name
 
| The name of the keyboard to find (eg Keyboard0)
 
| The name of the keyboard to find (eg Keyboard0)
 
|-
 
|-
! '''Return'''
+
! Return
 
| Pointer to keyboard device entry or nil if not found
 
| Pointer to keyboard device entry or nil if not found
 
|-
 
|-
Line 640: Line 1,183:
 
{| class="wikitable" style="font-size: 14px; background: white;"
 
{| class="wikitable" style="font-size: 14px; background: white;"
 
|-
 
|-
! '''Description'''
+
! Description
 
| The description of the keyboard to find (eg USB HID Keyboard)
 
| The description of the keyboard to find (eg USB HID Keyboard)
 
|-
 
|-
! '''Return'''
+
! Return
 
| Pointer to keyboard device entry or nil if not found
 
| Pointer to keyboard device entry or nil if not found
 
|-
 
|-
Line 655: Line 1,198:
 
{| class="wikitable" style="font-size: 14px; background: white;"
 
{| class="wikitable" style="font-size: 14px; background: white;"
 
|-
 
|-
! '''Callback'''
+
! Callback
 
| The callback function to call for each keyboard in the table
 
| The callback function to call for each keyboard in the table
 
|-
 
|-
! '''Data'''
+
! Data
 
| A private data pointer to pass to callback for each keyboard in the table
 
| A private data pointer to pass to callback for each keyboard in the table
 
|-
 
|-
! '''Return'''
+
! Return
 
| ERROR_SUCCESS if completed or another error code on failure
 
| ERROR_SUCCESS if completed or another error code on failure
 
|-
 
|-
Line 673: Line 1,216:
 
{| class="wikitable" style="font-size: 14px; background: white;"
 
{| class="wikitable" style="font-size: 14px; background: white;"
 
|-
 
|-
! '''Keyboard'''
+
! Keyboard
 
| The keyboard device to notify changes for (Optional, pass nil for all keyboards)
 
| The keyboard device to notify changes for (Optional, pass nil for all keyboards)
 
|-
 
|-
! '''Callback'''
+
! Callback
 
| The function to call when a notification event occurs
 
| The function to call when a notification event occurs
 
|-
 
|-
! '''Data'''
+
! Data
 
| A private data pointer to pass to callback when a notification event occurs
 
| A private data pointer to pass to callback when a notification event occurs
 
|-
 
|-
! '''Notification'''
+
! Notification
 
| The events to register for notification of (eg DEVICE_NOTIFICATION_REGISTER)
 
| The events to register for notification of (eg DEVICE_NOTIFICATION_REGISTER)
 
|-
 
|-
! '''Flags'''
+
! Flags
 
| The flags to control the notification (eg NOTIFIER_FLAG_WORKER)
 
| The flags to control the notification (eg NOTIFIER_FLAG_WORKER)
 
|-
 
|-
Line 700: Line 1,243:
 
{| class="wikitable" style="font-size: 14px; background: white;"
 
{| class="wikitable" style="font-size: 14px; background: white;"
 
|-
 
|-
! '''Note'''
+
! Note
 
| None documented
 
| None documented
 
|-
 
|-
Line 712: Line 1,255:
 
{| class="wikitable" style="font-size: 14px; background: white;"
 
{| class="wikitable" style="font-size: 14px; background: white;"
 
|-
 
|-
! '''Note'''
+
! Note
 
| None documented
 
| None documented
 
|-
 
|-
Line 724: Line 1,267:
 
{| class="wikitable" style="font-size: 14px; background: white;"
 
{| class="wikitable" style="font-size: 14px; background: white;"
 
|-
 
|-
! '''Note'''
+
! Note
 
| None documented
 
| None documented
 
|-
 
|-
Line 736: Line 1,279:
 
{| class="wikitable" style="font-size: 14px; background: white;"
 
{| class="wikitable" style="font-size: 14px; background: white;"
 
|-
 
|-
! '''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'''
 
| None documented
 
|-
 
|}
 
</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'''
 
| None documented
 
|-
 
|}
 
</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
 
|-
 
! '''Interface'''
 
| 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
 
|-
 
! '''Interface'''
 
| 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 836: 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;">
 
{| class="wikitable" style="font-size: 14px; background: white;"
 
{| class="wikitable" style="font-size: 14px; background: white;"
 
|-
 
|-
! '''Note'''
+
! Note
 
| None documented
 
| None documented
 
|-
 
|-
Line 853: Line 1,306:
 
{| class="wikitable" style="font-size: 14px; background: white;"
 
{| class="wikitable" style="font-size: 14px; background: white;"
 
|-
 
|-
! '''Note'''
+
! Note
 
| None documented
 
| None documented
 
|-
 
|-
Line 865: Line 1,318:
 
{| class="wikitable" style="font-size: 14px; background: white;"
 
{| class="wikitable" style="font-size: 14px; background: white;"
 
|-
 
|-
! '''Note'''
+
! Note
 
| None documented
 
| None documented
 
|-
 
|-
Line 877: Line 1,330:
 
{| class="wikitable" style="font-size: 14px; background: white;"
 
{| class="wikitable" style="font-size: 14px; background: white;"
 
|-
 
|-
! '''Note'''
+
! Note
 
| None documented
 
| None documented
 
|-
 
|-
Line 889: Line 1,342:
 
{| class="wikitable" style="font-size: 14px; background: white;"
 
{| class="wikitable" style="font-size: 14px; background: white;"
 
|-
 
|-
! '''Note'''
+
! Note
 
| None documented
 
| None documented
 
|-
 
|-
Line 901: Line 1,354:
 
{| class="wikitable" style="font-size: 14px; background: white;"
 
{| class="wikitable" style="font-size: 14px; background: white;"
 
|-
 
|-
! '''Note'''
+
! Note
 
| Caller must check for Left-Ctrl or Right-Ctrl modifiers
 
| Caller must check for Left-Ctrl or Right-Ctrl modifiers
 
|-
 
|-
Line 913: Line 1,366:
 
{| class="wikitable" style="font-size: 14px; background: white;"
 
{| class="wikitable" style="font-size: 14px; background: white;"
 
|-
 
|-
! '''Return'''
+
! Return
| Returns True if the key was remapped, False if it was not
+
| Returns True if the key was remapped, False if it was not.
 
|-
 
|-
! '''See'''
+
! See
| http://www.freepascal.org/docs-html/rtl/keyboard/kbdscancode.html See also: \source\packages\rtl-console\src\inc\keyscan.inc
+
| http://www.freepascal.org/docs-html/rtl/keyboard/kbdscancode.html  
 +
See also: \source\packages\rtl-console\src\inc\keyscan.inc
 
|-
 
|-
! '''Note'''
+
! Note
 
| See below for a version that uses SCAN_CODE_* values instead of translated KEY_CODE_* values
 
| See below for a version that uses SCAN_CODE_* values instead of translated KEY_CODE_* values
 
|-
 
|-
Line 931: Line 1,385:
 
{| class="wikitable" style="font-size: 14px; background: white;"
 
{| class="wikitable" style="font-size: 14px; background: white;"
 
|-
 
|-
! '''Return'''
+
! Return
 
| Returns True if the key was remapped, False if it was not
 
| Returns True if the key was remapped, False if it was not
 
|-
 
|-
! '''See'''
+
! See
| http://www.freepascal.org/docs-html/rtl/keyboard/kbdscancode.html See also: \source\packages\rtl-console\src\inc\keyscan.inc
+
| http://www.freepascal.org/docs-html/rtl/keyboard/kbdscancode.html  
 +
See also: \source\packages\rtl-console\src\inc\keyscan.inc
 
|-
 
|-
! '''Note'''
+
! Note
 
| Same as above except using SCAN_CODE_* values instead of translated KEY_CODE_* values
 
| Same as above except using SCAN_CODE_* values instead of translated KEY_CODE_* values
 
|-
 
|-
Line 944: Line 1,399:
 
<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;">procedure KeyboardLog(Level:LongWord; Keyboard:PKeyboardDevice; const AText:String);</pre>
+
<pre style="border: 0; padding-bottom:0px;">function KeyboardInsertData(Keyboard:PKeyboardDevice; Data:PKeyboardData; Signal:Boolean):LongWord;</pre>
<div style="font-size: 14px; padding-left: 12px;">'''Description:''' To be documented</div>
+
<div class="mw-collapsible-content" style="text-align: left; padding-left: 5px;">
+
{| class="wikitable" style="font-size: 14px; background: white;"
+
|-
+
! '''Note'''
+
| None documented
+
|-
+
|}
+
</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 KeyboardLogInfo(Keyboard:PKeyboardDevice; const AText:String);</pre>
+
<div style="font-size: 14px; padding-left: 12px;">'''Description:''' To be documented</div>
+
<div class="mw-collapsible-content" style="text-align: left; padding-left: 5px;">
+
{| class="wikitable" style="font-size: 14px; background: white;"
+
|-
+
! '''Note'''
+
| None documented
+
|-
+
|}
+
</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 KeyboardLogError(Keyboard:PKeyboardDevice; const AText:String);</pre>
+
<div style="font-size: 14px; padding-left: 12px;">'''Description:''' To be documented</div>
+
<div class="mw-collapsible-content" style="text-align: left; padding-left: 5px;">
+
{| class="wikitable" style="font-size: 14px; background: white;"
+
|-
+
! '''Note'''
+
| None documented
+
|-
+
|}
+
</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 KeyboardLogDebug(Keyboard:PKeyboardDevice; const AText:String);</pre>
+
<div style="font-size: 14px; padding-left: 12px;">'''Description:''' To be documented</div>
+
<div class="mw-collapsible-content" style="text-align: left; padding-left: 5px;">
+
{| class="wikitable" style="font-size: 14px; background: white;"
+
|-
+
! '''Note'''
+
| 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 USBKeyboardInsertData(Keyboard:PUSBKeyboardDevice; Data:PKeyboardData):LongWord;</pre>
+
 
<div style="font-size: 14px; padding-left: 12px;">'''Description:''' Insert a TKeyboardData entry into the keyboard buffer (Direct or Global)</div>
 
<div style="font-size: 14px; padding-left: 12px;">'''Description:''' Insert a TKeyboardData entry into the keyboard buffer (Direct or Global)</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;"
 
|-
 
|-
! '''Keyboard'''
+
! Keyboard
| The USB keyboard device to insert data for
+
| The keyboard device to insert data for
 
|-
 
|-
! '''Data'''
+
! Data
 
| The TKeyboardData entry to insert
 
| The TKeyboardData entry to insert
 
|-
 
|-
! '''Return'''
+
! Signal
 +
| If True then signal that new data is available in the buffer
 +
|-
 +
! Return
 
| ERROR_SUCCESS if completed or another error code on failure
 
| ERROR_SUCCESS if completed or another error code on failure
 
|-
 
|-
! '''Note'''
+
! Note
 
| Caller must hold the keyboard lock
 
| Caller must hold the keyboard lock
 
|-
 
|-
Line 1,016: Line 1,423:
 
<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 USBKeyboardCheckPressed(Keyboard:PUSBKeyboardDevice; ScanCode:Byte):Boolean;</pre>
+
<pre style="border: 0; padding-bottom:0px;">procedure KeyboardLog(Level:LongWord; Keyboard:PKeyboardDevice; const AText:String);</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 style="font-size: 14px; padding-left: 12px;">'''Description:''' To be documented</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;"
 
|-
 
|-
! '''Keyboard'''
+
! Note
| The USB keyboard device to check for
+
| None documented
|-
+
! '''ScanCode'''
+
| The keyboard scan code to check
+
|-
+
! '''Note'''
+
| Caller must hold the keyboard lock
+
 
|-
 
|-
 
|}
 
|}
Line 1,034: Line 1,435:
 
<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 USBKeyboardCheckRepeated(Keyboard:PUSBKeyboardDevice; ScanCode:Byte):Boolean;</pre>
+
<pre style="border: 0; padding-bottom:0px;">procedure KeyboardLogInfo(Keyboard:PKeyboardDevice; const AText:String); inline;</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 style="font-size: 14px; padding-left: 12px;">'''Description:''' To be documented</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;"
 
|-
 
|-
! '''Keyboard'''
+
! Note
| The USB keyboard device to check for
+
| None documented
|-
+
! '''ScanCode'''
+
| The keyboard scan code to check
+
|-
+
! '''Note'''
+
| Caller must hold the keyboard lock
+
 
|-
 
|-
 
|}
 
|}
Line 1,052: Line 1,447:
 
<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 USBKeyboardCheckReleased(Keyboard:PUSBKeyboardDevice; Report:PUSBKeyboardReport; ScanCode:Byte):Boolean;</pre>
+
<pre style="border: 0; padding-bottom:0px;">procedure KeyboardLogWarn(Keyboard:PKeyboardDevice; const AText:String); inline;</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 style="font-size: 14px; padding-left: 12px;">'''Description:''' To be documented</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;"
 
|-
 
|-
! '''Keyboard'''
+
! Note
| The USB keyboard device to check for
+
| None documented
|-
+
! '''Report'''
+
| The USB keyboard report to compare against (Current)
+
|-
+
! '''ScanCode'''
+
| The keyboard scan code to check
+
|-
+
! '''Note'''
+
| Caller must hold the keyboard lock
+
 
|-
 
|-
 
|}
 
|}
Line 1,073: Line 1,459:
 
<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 USBKeyboardDeviceSetLEDs(Keyboard:PUSBKeyboardDevice; LEDs:Byte):LongWord;</pre>
+
<pre style="border: 0; padding-bottom:0px;">procedure KeyboardLogError(Keyboard:PKeyboardDevice; const AText:String); inline;</pre>
<div style="font-size: 14px; padding-left: 12px;">'''Description:''' Set the state of the LEDs for a USB keyboard device</div>
+
<div style="font-size: 14px; padding-left: 12px;">'''Description:''' To be documented</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;"
 
|-
 
|-
! '''Keyboard'''
+
! Note
| The USB keyboard device to set the LEDs for
+
| None documented
|-
+
! '''LEDs'''
+
| The LED state to set (eg KEYBOARD_LED_NUMLOCK)
+
|-
+
! '''Return'''
+
| USB_STATUS_SUCCESS if completed or another USB error code on failure
+
 
|-
 
|-
 
|}
 
|}
Line 1,091: Line 1,471:
 
<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 USBKeyboardDeviceSetIdle(Keyboard:PUSBKeyboardDevice; Duration,ReportId:Byte):LongWord;</pre>
+
<pre style="border: 0; padding-bottom:0px;">procedure KeyboardLogDebug(Keyboard:PKeyboardDevice; const AText:String); inline;</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 style="font-size: 14px; padding-left: 12px;">'''Description:''' To be documented</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;"
 
|-
 
|-
! '''Keyboard'''
+
! Note
| The USB keyboard device to set the idle duration for
+
| None documented
|-
+
! '''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
+
 
|-
 
|-
 
|}
 
|}

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



Keyboard specific constants KEYBOARD_NAME_*
KEYBOARD_NAME_PREFIX = 'Keyboard'; Name prefix for Keyboard Devices


Keyboard device type KEYBOARD_TYPE_*
KEYBOARD_TYPE_NONE = 0;  
KEYBOARD_TYPE_USB = 1;  
KEYBOARD_TYPE_PS2 = 2;  
KEYBOARD_TYPE_SERIAL = 3;  
 
KEYBOARD_TYPE_MAX = 3;  


Keyboard device state KEYBOARD_STATE_*
KEYBOARD_STATE_DETACHED = 0;  
KEYBOARD_STATE_DETACHING = 1;  
KEYBOARD_STATE_ATTACHING = 2;  
KEYBOARD_STATE_ATTACHED = 3;  
 
KEYBOARD_STATE_MAX = 3;  


Keyboard device flag KEYBOARD_FLAG_*
KEYBOARD_FLAG_NON_BLOCK = $00000001; If set device reads are non blocking (Also supported in Flags parameter of KeyboardReadEx)
KEYBOARD_FLAG_DIRECT_READ = $00000002; If set device writes keyboard data to its local buffer which must be read using KeyboardDeviceRead
KEYBOARD_FLAG_PEEK_BUFFER = $00000004; Peek at the buffer to see if any data is available, don't remove it (Used only in Flags parameter of KeyboardReadEx)
KEYBOARD_FLAG_PEEK_BUFFER = $00000004;  
 
KEYBOARD_FLAG_MASK = KEYBOARD_FLAG_NON_BLOCK or KEYBOARD_FLAG_DIRECT_READ or KEYBOARD_FLAG_PEEK_BUFFER;


Keyboard device control code KEYBOARD_CONTROL_*
KEYBOARD_CONTROL_GET_FLAG = 1; Get Flag
KEYBOARD_CONTROL_SET_FLAG = 2; Set Flag
KEYBOARD_CONTROL_CLEAR_FLAG = 3; Clear Flag
KEYBOARD_CONTROL_FLUSH_BUFFER = 4; Flush Buffer
KEYBOARD_CONTROL_GET_LED = 5; Get LED
KEYBOARD_CONTROL_SET_LED = 6; Set LED
KEYBOARD_CONTROL_CLEAR_LED = 7; Clear LED
KEYBOARD_CONTROL_GET_REPEAT_RATE = 8; Get Repeat Rate
KEYBOARD_CONTROL_SET_REPEAT_RATE = 9; Set Repeat Rate
KEYBOARD_CONTROL_GET_REPEAT_DELAY = 10; Get Repeat Delay
KEYBOARD_CONTROL_SET_REPEAT_DELAY = 11; Set Repeat Delay


Keyboard device LED KEYBOARD_LED_*
KEYBOARD_LED_NONE = $00000000;  
KEYBOARD_LED_NUMLOCK = $00000001;  
KEYBOARD_LED_CAPSLOCK = $00000002;  
KEYBOARD_LED_SCROLLLOCK = $00000004;  
KEYBOARD_LED_COMPOSE = $00000008;  
KEYBOARD_LED_KANA = $00000010;  
 
KEYBOARD_LED_MASK = KEYBOARD_LED_NUMLOCK or KEYBOARD_LED_CAPSLOCK or KEYBOARD_LED_SCROLLLOCK or KEYBOARD_LED_COMPOSE or KEYBOARD_LED_KANA;


Keyboard buffer size KEYBOARD_BUFFER_*
KEYBOARD_BUFFER_SIZE = 512;  


Keyboard sampling rate KEYBOARD_REPEAT_*
KEYBOARD_REPEAT_RATE = 40; 40msec -> 25cps
KEYBOARD_REPEAT_DELAY = 10; 10 x KEYBOARD_REPEAT_RATE = 400msec initial delay before repeat


Keyboard data definition KEYBOARD_*
Values for TKeyboardData.Modifiers
 
KEYBOARD_LEFT_CTRL = $00000001; The Left Control key is pressed
KEYBOARD_LEFT_SHIFT = $00000002; The Left Shift key is pressed
KEYBOARD_LEFT_ALT = $00000004; The Left Alt key is pressed
KEYBOARD_LEFT_GUI = $00000008; The Left GUI (or Windows) key is pressed
KEYBOARD_RIGHT_CTRL = $00000010; The Right Control key is pressed
KEYBOARD_RIGHT_SHIFT = $00000020; The Right Shift key is pressed
KEYBOARD_RIGHT_ALT = $00000040; The Right Alt key is pressed
KEYBOARD_RIGHT_GUI = $00000080; The Right GUI (or Windows) key is pressed
KEYBOARD_NUM_LOCK = $00000100; Num Lock is currently on
KEYBOARD_CAPS_LOCK = $00000200; Caps Lock is currently on
KEYBOARD_SCROLL_LOCK = $00000400; Scroll Lock is currently on
KEYBOARD_COMPOSE = $00000800; Compose is currently on
KEYBOARD_KANA = $00001000; Kana is currently on
KEYBOARD_KEYUP = $00002000; The key state changed to up
KEYBOARD_KEYDOWN = $00004000; The key state changed to down
KEYBOARD_KEYREPEAT = $00008000; The key is being repeated
KEYBOARD_DEADKEY = $00010000; The key is a being handled as a deadkey}
KEYBOARD_ALTGR = $00020000; The AltGr key is pressed (Normally also Right Alt but may be Ctrl-Alt)


Keyboard logging KEYBOARD_LOG_*
KEYBOARD_LOG_LEVEL_DEBUG = LOG_LEVEL_DEBUG; Keyboard debugging messages
KEYBOARD_LOG_LEVEL_INFO = LOG_LEVEL_INFO; Keyboard informational messages, such as a device being attached or detached
KEYBOARD_LOG_LEVEL_WARN = LOG_LEVEL_WARN; Keyboard warning messages
KEYBOARD_LOG_LEVEL_ERROR = LOG_LEVEL_ERROR; Keyboard error messages
KEYBOARD_LOG_LEVEL_NONE = LOG_LEVEL_NONE; No Keyboard messages


USB keyboard specific constants USBKEYBOARD_*
Note: The following constants are duplicated with the USBKeyboard unit for backwards compatibility


USB HID interface subclass USB_HID_SUBCLASS_*
See USB HID v1.11 specification
 
USB_HID_SUBCLASS_NONE = 0; Section 4.2
USB_HID_SUBCLASS_BOOT = 1; Section 4.2


USB HID interface protocol USB_HID_BOOT_PROTOCOL_*
See USB HID v1.11 specification
 
USB_HID_BOOT_PROTOCOL_NONE = 0; Section 4.3
USB_HID_BOOT_PROTOCOL_KEYBOARD = 1; Section 4.3
USB_HID_BOOT_PROTOCOL_MOUSE = 2; Section 4.3


USB HID class descriptor USB_HID_DESCRIPTOR_*
See USB HID v1.11 specification
 
USB_HID_DESCRIPTOR_TYPE_HID = $21; Section 7.1
USB_HID_DESCRIPTOR_TYPE_REPORT = $22; Section 7.1
USB_HID_DESCRIPTOR_TYPE_PHYSICAL_DESCRIPTOR = $23; Section 7.1


USB HID request USB_HID_REQUEST_*
See USB HID v1.11 specification
 
USB_HID_REQUEST_GET_REPORT = $01; Section 7.2
USB_HID_REQUEST_GET_IDLE = $02; Section 7.2
USB_HID_REQUEST_GET_PROTOCOL = $03; Section 7.2
USB_HID_REQUEST_SET_REPORT = $09; Section 7.2
USB_HID_REQUEST_SET_IDLE = $0A; Section 7.2
USB_HID_REQUEST_SET_PROTOCOL = $0B; Section 7.2


USB HID protocol USB_HID_PROTOCOL_*
See USB HID v1.11 specification
 
USB_HID_PROTOCOL_BOOT = 0; Section 7.2.5
USB_HID_PROTOCOL_REPORT = 1; Section 7.2.5


USB HID report USB_HID_REPORT_*
See USB HID v1.11 specification
 
USB_HID_REPORT_INPUT = 1; Section 7.2.1
USB_HID_REPORT_OUTPUT = 2; Section 7.2.1
USB_HID_REPORT_FEATURE = 3; Section 7.2.1


USB HID report Ids USB_HID_REPORTID_*
See USB HID v1.11 specification
 
USB_HID_REPORTID_NONE = 0; Section 7.2.1


USB HID boot protocol USB_HID_BOOT_LEFT_*, USB_HID_BOOT_RIGHT_*
USB_HID_BOOT_LEFT_CTRL = (1 shl 0);  
USB_HID_BOOT_LEFT_SHIFT = (1 shl 1);  
USB_HID_BOOT_LEFT_ALT = (1 shl 2);  
USB_HID_BOOT_LEFT_GUI = (1 shl 3);  
USB_HID_BOOT_RIGHT_CTRL = (1 shl 4);  
USB_HID_BOOT_RIGHT_SHIFT = (1 shl 5);  
USB_HID_BOOT_RIGHT_ALT = (1 shl 6);  
USB_HID_BOOT_RIGHT_GUI = (1 shl 7);  


USB HID boot protocol report data USB_HID_BOOT_REPORT_*
USB_HID_BOOT_REPORT_SIZE = 8; Appendix B of HID Device Class Definition 1.11


USB HID boot protocol output USB_HID_BOOT_*_LED
USB_HID_BOOT_NUMLOCK_LED = (1 shl 0);  
USB_HID_BOOT_CAPSLOCK_LED = (1 shl 1);  
USB_HID_BOOT_SCROLLLOCK_LED = (1 shl 2);  
USB_HID_BOOT_COMPOSE_LED = (1 shl 3);  
USB_HID_BOOT_KANA_LED = (1 shl 4);  
 
USB_HID_BOOT_LEDMASK = USB_HID_BOOT_NUMLOCK_LED or USB_HID_BOOT_CAPSLOCK_LED or USB_HID_BOOT_SCROLLLOCK_LED or USB_HID_BOOT_COMPOSE_LED or USB_HID_BOOT_KANA_LED;  


USB HID boot protocol output data USB_HID_BOOT_OUTPUT_*
USB_HID_BOOT_OUTPUT_SIZE = 1; Appendix B of HID Device Class Definition 1.11
 
USB_HID_BOOT_USAGE_NUMLOCK = SCAN_CODE_NUMLOCK; 83
USB_HID_BOOT_USAGE_CAPSLOCK = SCAN_CODE_CAPSLOCK; 57
USB_HID_BOOT_USAGE_SCROLLLOCK = SCAN_CODE_SCROLLLOCK; 71


Type definitions



Keyboard data

PKeyboardData = ^TKeyboardData;

TKeyboardData = record

Modifiers:LongWord; Keyboard modifier flags for Shift, Alt, Control etc (eg KEYBOARD_LEFT_CTRL)
ScanCode:Word; Untranslated scan code value from keyboard (See SCAN_CODE_* constants)
KeyCode:Word; Translated key code value from keyboard (See KEY_CODE_* constants)
CharCode:Char; ANSI character representing the translated key code
CharUnicode:WideChar; Unicode character representing the translated key code

Keyboard buffer

PKeyboardBuffer = ^TKeyboardBuffer;

TKeyboardBuffer = record

Wait:TSemaphoreHandle; Data ready semaphore
Start:LongWord; Index of first buffer ready
Count:LongWord; Number of messages ready in buffer
Buffer:array[0..(KEYBOARD_BUFFER_SIZE - 1)] of TKeyboardData;  

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

PKeyboardDevice = ^TKeyboardDevice;

TKeyboardDevice = record

Device Properties
Device:TDevice; The Device entry for this Keyboard
Keyboard Properties
KeyboardId:LongWord; Unique Id of this Keyboard in the Keyboard table
KeyboardState:LongWord; Keyboard state (eg KEYBOARD_STATE_ATTACHED)
KeyboardLEDs:LongWord; Keyboard LEDs (eg KEYBOARD_LED_NUMLOCK)
KeyboardRate:LongWord; Keyboard repeat rate (Milliseconds)
KeyboardDelay:LongWord; Keyboard repeat delay (Number of KeyboardRate intervals before first repeat)
DeviceGet:TKeyboardDeviceGet; A Device specific DeviceGet method implementing a standard Keyboard device interface (Or nil if the default method is suitable)
DeviceRead:TKeyboardDeviceRead; A Device specific DeviceRead method implementing a standard Keyboard device interface (Or nil if the default method is suitable)
DeviceControl:TKeyboardDeviceControl; A Device specific DeviceControl method implementing a standard Keyboard device interface (Or nil if the default method is suitable)
Driver Properties
Lock:TMutexHandle; Keyboard lock
Code:Word; Scan code of current deadkey (If Applicable)
Index:Word; Index state for current deadkey (If Applicable)
Modifiers:LongWord; Modifier state for current deadkey (If Applicable)
Buffer:TKeyboardBuffer; Keyboard input buffer
Statistics Properties
ReceiveCount:LongWord;  
ReceiveErrors:LongWord;  
BufferOverruns:LongWord;  
Internal Properties
Prev:PKeyboardDevice; Previous entry in Keyboard table
Next:PKeyboardDevice; Next entry in Keyboard table

USB HID descriptor

PUSBHIDDescriptor = ^TUSBHIDDescriptor;

TUSBHIDDescriptor = packed record

bLength:Byte;  
bDescriptorType:Byte;  
bcdHID:Word;  
bCountryCode:Byte;  
bNumDescriptors:Byte;  
bHIDDescriptorType:Byte;  
wHIDDescriptorLength:Word;  
Note: Up to two optional bHIDDescriptorType/wHIDDescriptorLength pairs after the Report descriptor details

USB keyboard report

PUSBKeyboardReport = ^TUSBKeyboardReport;

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

   

USB keyboard device

PUSBKeyboardDevice = ^TUSBKeyboardDevice;

TUSBKeyboardDevice = record

Keyboard Properties
Keyboard:TKeyboardDevice;  
USB Properties
HIDInterface:PUSBInterface; USB HID Keyboard Interface
ReportRequest:PUSBRequest; USB request for keyboard report data
ReportEndpoint:PUSBEndpointDescriptor; USB Keyboard Interrupt IN Endpoint
HIDDescriptor:PUSBHIDDescriptor; USB HID Descriptor for keyboard
ReportDescriptor:Pointer; USB HID Report Descriptor for keyboard
LastCode:Word; The scan code of the last key pressed
LastCount:LongWord; The repeat count of the last key pressed
LastReport:TUSBKeyboardReport; The last keyboard report received
PendingCount:LongWord; Number of USB requests pending for this keyboard
WaiterThread:TThreadId; Thread waiting for pending requests to complete (for keyboard detachment)


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

procedure KeyboardInit;
Description: Initialize the keyboard unit and device table
Note Called only during system startup


Keyboard functions

function KeyboardGet(var KeyCode:Word):LongWord;
Description: Get the first key code from the global keyboard buffer
KeyCode The returned key code read from the buffer (eg KEY_CODE_A)
Return 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()


function KeyboardPeek:LongWord;
Description: Peek at the global keyboard buffer to see if any data packets are ready
Return ERROR_SUCCESS if packets are ready, ERROR_NO_MORE_ITEMS if not or another error code on failure.


function KeyboardRead(Buffer:Pointer; Size:LongWord; var Count:LongWord):LongWord; inline;
Description: Read keyboard data packets from the global keyboard buffer
Buffer Pointer to a buffer to copy the keyboard data packets to
Size The size of the buffer in bytes (Must be at least TKeyboardData or greater)
Count The number of keyboard data packets copied to the buffer
Return ERROR_SUCCESS if completed or another error code on failure


function KeyboardReadEx(Buffer:Pointer; Size,Flags:LongWord; var Count:LongWord):LongWord;
Description: Read keyboard data packets from the global keyboard buffer
Buffer Pointer to a buffer to copy the keyboard data packets to
Size TThe size of the buffer in bytes (Must be at least TKeyboardData or greater)
Flags The flags to use for the read (eg KEYBOARD_FLAG_NON_BLOCK)
Count The number of keyboard data packets copied to the buffer
Return ERROR_SUCCESS if completed or another error code on failure


function KeyboardPut(ScanCode,KeyCode:Word; Modifiers:LongWord):LongWord;
Description: Put a scan code and key code in the global keyboard buffer
ScanCode The scan code to write to the buffer (eg SCAN_CODE_A)
KeyCode The key code to write to the buffer (eg KEY_CODE_A)
Modifiers The modifier keys to write to the buffer (eg KEYBOARD_LEFT_CTRL)
Return ERROR_SUCCESS if completed or another error code on failure


function KeyboardWrite(Buffer:Pointer; Size,Count:LongWord):LongWord;
Description: Write keyboard data packets to the global keyboard buffer
Buffer Pointer to a buffer to copy the keyboard data packets from
Size The size of the buffer in bytes (Must be at least TKeyboardData or greater)
Count The number of keyboard data packets to copy from the buffer
Return ERROR_SUCCESS if completed or another error code on failure


function KeyboardFlush:LongWord;
Description: Flush the contents of the global keyboard buffer
Return ERROR_SUCCESS if completed or another error code on failure


function KeyboardDeviceGet(Keyboard:PKeyboardDevice; var KeyCode:Word):LongWord;
Description: Get the first key code from the buffer of the specified keyboard
Keyboard The keyboard device to get from
Keycode The returned key code read from the buffer (eg KEY_CODE_A)
Return 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()


function KeyboardDeviceRead(Keyboard:PKeyboardDevice; Buffer:Pointer; Size:LongWord; var Count:LongWord):LongWord;
Description: Read keyboard data packets from the buffer of the specified keyboard
Keyboard The keyboard device to read from
Buffer Pointer to a buffer to copy the keyboard data packets to
Size The size of the buffer in bytes (Must be at least TKeyboardData or greater)
Count The number of keyboard data packets copied to the buffer
Return ERROR_SUCCESS if completed or another error code on failure


function KeyboardDeviceControl(Keyboard:PKeyboardDevice; Request:Integer; Argument1:PtrUInt; var Argument2:PtrUInt):LongWord;
Description: Perform a control request on the specified keyboard device
Keyboard The keyboard device to control
Request The request code for the operation (eg KEYBOARD_CONTROL_GET_FLAG)
Argument1 The first argument for the operation (Dependent on request code)
Argument2 The second argument for the operation (Dependent on request code)
Return ERROR_SUCCESS if completed or another error code on failure


function KeyboardDeviceSetState(Keyboard:PKeyboardDevice; State:LongWord):LongWord;
Description: Set the state of the specified keyboard and send a notification
Keyboard The keyboard to set the state for
State The new state to set and notify
Return ERROR_SUCCESS if completed or another error code on failure


function KeyboardDeviceCreate:PKeyboardDevice;
Description: Create a new Keyboard device entry
Return Pointer to new Keyboard device entry or nil if keyboard could not be created


function KeyboardDeviceCreateEx(Size:LongWord):PKeyboardDevice;
Description: Create a new Keyboard device entry
Size Size in bytes to allocate for new keyboard (Including the keyboard device entry)
Return Pointer to new Keyboard device entry or nil if keyboard could not be created


function KeyboardDeviceDestroy(Keyboard:PKeyboardDevice):LongWord;
Description: Destroy an existing Keyboard device entry
Keyboard The keyboard device to destroy
Return ERROR_SUCCESS if completed or another error code on failure


function KeyboardDeviceRegister(Keyboard:PKeyboardDevice):LongWord;
Description: Register a new Keyboard device in the Keyboard table
Keyboard The keyboard device to register
Return ERROR_SUCCESS if completed or another error code on failure


function KeyboardDeviceDeregister(Keyboard:PKeyboardDevice):LongWord;
Description: Deregister a Keyboard device from the Keyboard table
Keyboard The keyboard device to deregister
Return ERROR_SUCCESS if completed or another error code on failure


function KeyboardDeviceFind(KeyboardId:LongWord):PKeyboardDevice;
Description: Find a keyboard device by ID in the keyboard table
KeyboardId The ID number of the keyboard to find
Return Pointer to keyboard device entry or nil if not found


function KeyboardDeviceFindByName(const Name:String):PKeyboardDevice; inline;
Description: Find a keyboard device by name in the keyboard table
Name The name of the keyboard to find (eg Keyboard0)
Return Pointer to keyboard device entry or nil if not found


function KeyboardDeviceFindByDescription(const Description:String):PKeyboardDevice; inline;
Description: Find a keyboard device by description in the keyboard table
Description The description of the keyboard to find (eg USB HID Keyboard)
Return Pointer to keyboard device entry or nil if not found


function KeyboardDeviceEnumerate(Callback:TKeyboardEnumerate; Data:Pointer):LongWord;
Description: Enumerate all keyboard devices in the keyboard table
Callback The callback function to call for each keyboard in the table
Data A private data pointer to pass to callback for each keyboard in the table
Return ERROR_SUCCESS if completed or another error code on failure


function KeyboardDeviceNotification(Keyboard:PKeyboardDevice; Callback:TKeyboardNotification; Data:Pointer; Notification,Flags:LongWord):LongWord;
Description: Register a notification for keyboard device changes
Keyboard The keyboard device to notify changes for (Optional, pass nil for all keyboards)
Callback The function to call when a notification event occurs
Data A private data pointer to pass to callback when a notification event occurs
Notification The events to register for notification of (eg DEVICE_NOTIFICATION_REGISTER)
Flags The flags to control the notification (eg NOTIFIER_FLAG_WORKER)


RTL console functions

function SysConsoleGetKey(var ACh:Char; AUserData:Pointer):Boolean;
Description: Handler for Platform ConsoleGetKey function
Note None documented


function SysConsolePeekKey(var ACh:Char; AUserData:Pointer):Boolean;
Description: Handler for Platform ConsolePeekKey function
Note None documented


function SysConsoleReadChar(var ACh:Char; AUserData:Pointer):Boolean;
Description: Handler for Platform ConsoleReadChar function
Note None documented


function SysConsoleReadWideChar(var ACh:WideChar; AUserData:Pointer):Boolean;
Description: Handler for Platform ConsoleReadWideChar function
Note None documented


Keyboard helper functions

function KeyboardGetCount:LongWord;
Description: Get the current keyboard count
Note None documented


function KeyboardDeviceCheck(Keyboard:PKeyboardDevice):PKeyboardDevice;
Description: Check if the supplied Keyboard is in the keyboard table
Note None documented


function KeyboardDeviceTypeToString(KeyboardType:LongWord):String;
Description: To be documented
Note None documented


function KeyboardDeviceStateToString(KeyboardState:LongWord):String;
Description: To be documented
Note None documented


function KeyboardDeviceStateToNotification(State:LongWord):LongWord;
Description: Convert a Keyboard state value into the notification code for device notifications
Note None documented


function KeyboardRemapCtrlCode(KeyCode,CharCode:Word):Word;
Description: Remap Ctrl-<Key> combinations to ASCII control codes
Note Caller must check for Left-Ctrl or Right-Ctrl modifiers


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
Return Returns True if the key was remapped, False if it was not.
See http://www.freepascal.org/docs-html/rtl/keyboard/kbdscancode.html

See also: \source\packages\rtl-console\src\inc\keyscan.inc

Note See below for a version that uses SCAN_CODE_* values instead of translated KEY_CODE_* values


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
Return Returns True if the key was remapped, False if it was not
See http://www.freepascal.org/docs-html/rtl/keyboard/kbdscancode.html

See also: \source\packages\rtl-console\src\inc\keyscan.inc

Note Same as above except using SCAN_CODE_* values instead of translated KEY_CODE_* values


function KeyboardInsertData(Keyboard:PKeyboardDevice; Data:PKeyboardData; Signal:Boolean):LongWord;
Description: Insert a TKeyboardData entry into the keyboard buffer (Direct or Global)
Keyboard The keyboard device to insert data for
Data The TKeyboardData entry to insert
Signal If True then signal that new data is available in the buffer
Return ERROR_SUCCESS if completed or another error code on failure
Note Caller must hold the keyboard lock


procedure KeyboardLog(Level:LongWord; Keyboard:PKeyboardDevice; const AText:String);
Description: To be documented
Note None documented


procedure KeyboardLogInfo(Keyboard:PKeyboardDevice; const AText:String); inline;
Description: To be documented
Note None documented


procedure KeyboardLogWarn(Keyboard:PKeyboardDevice; const AText:String); inline;
Description: To be documented
Note None documented


procedure KeyboardLogError(Keyboard:PKeyboardDevice; const AText:String); inline;
Description: To be documented
Note None documented


procedure KeyboardLogDebug(Keyboard:PKeyboardDevice; const AText:String); inline;
Description: To be documented
Note None documented


Return to Unit Reference