Difference between revisions of "Unit Keyboard"

From Ultibo.org
Jump to: navigation, search
Line 16: Line 16:
 
----
 
----
  
''To be documented''
+
 
 +
<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 specific constants''' <code> KEYBOARD_NAME_* </code></div>
 +
<div class="mw-collapsible-content" style="text-align: left; padding-left: 5px;">
 +
{| class="wikitable" style="font-size: 14px; background: white;"
 +
|-
 +
| <code>KEYBOARD_NAME_PREFIX = 'Keyboard';</code>
 +
| Name prefix for Keyboard Devices
 +
|-
 +
|}
 +
</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;">'''Keyboard device type constants''' <code> KEYBOARD_TYPE_* </code></div>
 +
<div class="mw-collapsible-content" style="text-align: left; padding-left: 5px;">
 +
{| class="wikitable" style="font-size: 14px; background: white;"
 +
|-
 +
| <code>KEYBOARD_TYPE_NONE = 0;</code>
 +
| style="width: 50%;"|&nbsp;
 +
|-
 +
| <code>KEYBOARD_TYPE_USB = 1;</code>
 +
| &nbsp;
 +
|-
 +
| <code>KEYBOARD_TYPE_PS2 = 2;</code>
 +
| &nbsp;
 +
|-
 +
| <code>KEYBOARD_TYPE_SERIAL = 3;</code>
 +
| &nbsp;
 +
|-
 +
|colspan="2"|&nbsp;
 +
|-
 +
| <code>KEYBOARD_TYPE_MAX = 3;</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;">'''Keyboard device state constants''' <code> KEYBOARD_STATE_* </code></div>
 +
<div class="mw-collapsible-content" style="text-align: left; padding-left: 5px;">
 +
{| class="wikitable" style="font-size: 14px; background: white;"
 +
|-
 +
| <code>KEYBOARD_STATE_DETACHED = 0;</code>
 +
| style="width: 50%;"|&nbsp;
 +
|-
 +
| <code>KEYBOARD_STATE_DETACHING = 1;</code>
 +
| &nbsp;
 +
|-
 +
| <code>KEYBOARD_STATE_ATTACHING = 2;</code>
 +
| &nbsp;
 +
|-
 +
| <code>KEYBOARD_STATE_ATTACHED = 3;</code>
 +
| &nbsp;
 +
|-
 +
|colspan="2"|&nbsp;
 +
|-
 +
| <code>KEYBOARD_STATE_MAX = 3;</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;">'''Keyboard device flag constants''' <code> KEYBOARD_FLAG_* </code></div>
 +
<div class="mw-collapsible-content" style="text-align: left; padding-left: 5px;">
 +
{| 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>
 +
| &nbsp;
 +
|-
 +
| <code>KEYBOARD_FLAG_DIRECT_READ = $00000002;</code>
 +
| &nbsp;
 +
|-
 +
| <code>KEYBOARD_FLAG_PEEK_BUFFER = $00000004;</code>
 +
| &nbsp;
 +
|-
 +
|colspan="2"|&nbsp;
 +
|-
 +
|colspan="2"|<code>KEYBOARD_FLAG_MASK = KEYBOARD_FLAG_NON_BLOCK or KEYBOARD_FLAG_DIRECT_READ or KEYBOARD_FLAG_PEEK_BUFFER;</code>
 +
|-
 +
|}
 +
</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;">'''Keyboard device control code constants''' <code> KEYBOARD_CONTROL_* </code></div>
 +
<div class="mw-collapsible-content" style="text-align: left; padding-left: 5px;">
 +
{| class="wikitable" style="font-size: 14px; background: white;"
 +
|-
 +
| <code>KEYBOARD_CONTROL_GET_FLAG = 1;</code>
 +
| Get Flag
 +
|-
 +
| <code> KEYBOARD_CONTROL_SET_FLAG = 2;</code>
 +
| Set Flag
 +
|-
 +
| <code>KEYBOARD_CONTROL_CLEAR_FLAG = 3;</code>
 +
| Clear Flag
 +
|-
 +
| <code>KEYBOARD_CONTROL_FLUSH_BUFFER = 4;</code>
 +
| Flush Buffer
 +
|-
 +
| <code>KEYBOARD_CONTROL_GET_LED = 5;</code>
 +
| Get LED
 +
|-
 +
| <code>KEYBOARD_CONTROL_SET_LED = 6;</code>
 +
| Set LED
 +
|-
 +
| <code>KEYBOARD_CONTROL_CLEAR_LED = 7;</code>
 +
| Clear LED
 +
|-
 +
| <code>KEYBOARD_CONTROL_GET_REPEAT_RATE = 8;</code>
 +
| Get Repeat Rate
 +
|-
 +
| <code>KEYBOARD_CONTROL_SET_REPEAT_RATE = 9;</code>
 +
| Set Repeat Rate
 +
|-
 +
| <code>KEYBOARD_CONTROL_GET_REPEAT_DELAY = 10;</code>
 +
| Get Repeat Delay
 +
|-
 +
| <code>KEYBOARD_CONTROL_SET_REPEAT_DELAY = 11;</code>
 +
| Set Repeat Delay
 +
|-
 +
|}
 +
</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;">'''Keyboard device LED constants''' <code> KEYBOARD_LED_* </code></div>
 +
<div class="mw-collapsible-content" style="text-align: left; padding-left: 5px;">
 +
{| class="wikitable" style="font-size: 14px; background: white;"
 +
|-
 +
| <code>KEYBOARD_LED_NONE = $00000000;</code>
 +
| style="width: 50%;"|&nbsp;
 +
|-
 +
| <code>KEYBOARD_LED_NUMLOCK = $00000001;</code>
 +
| &nbsp;
 +
|-
 +
| <code>KEYBOARD_LED_CAPSLOCK = $00000002;</code>
 +
| &nbsp;
 +
|-
 +
| <code>KEYBOARD_LED_SCROLLLOCK = $00000004;</code>
 +
| &nbsp;
 +
|-
 +
| <code>KEYBOARD_LED_COMPOSE = $00000008;</code>
 +
| &nbsp;
 +
|-
 +
| <code>KEYBOARD_LED_KANA = $00000010;</code>
 +
| &nbsp;
 +
|-
 +
|colspan="2"|&nbsp;
 +
|-
 +
|colspan="2"|<code>KEYBOARD_LED_MASK = KEYBOARD_LED_NUMLOCK or KEYBOARD_LED_CAPSLOCK or KEYBOARD_LED_SCROLLLOCK or KEYBOARD_LED_COMPOSE or KEYBOARD_LED_KANA;</code>
 +
|-
 +
|}
 +
</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;">'''Keyboard buffer size constants''' <code> KEYBOARD_BUFFER_* </code></div>
 +
<div class="mw-collapsible-content" style="text-align: left; padding-left: 5px;">
 +
{| class="wikitable" style="font-size: 14px; background: white;"
 +
|-
 +
| <code>KEYBOARD_BUFFER_SIZE = 512;</code>
 +
| style="width: 50%;"|&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;">'''Keyboard sampling rate constants''' <code> KEYBOARD_REPEAT_* </code></div>
 +
<div class="mw-collapsible-content" style="text-align: left; padding-left: 5px;">
 +
{| class="wikitable" style="font-size: 14px; background: white;"
 +
|-
 +
| <code>KEYBOARD_REPEAT_RATE = (40 div 4);</code>
 +
| 40msec -> 25cps
 +
|-
 +
| <code>KEYBOARD_REPEAT_DELAY = 10;</code>
 +
| 10 x KEYBOARD_REPEAT_RATE = 400msec initial delay before repeat
 +
|-
 +
|}
 +
</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;">'''Keyboard data definition constants''' <code> KEYBOARD_* </code></div>
 +
<div class="mw-collapsible-content" style="text-align: left; padding-left: 5px;">
 +
{| class="wikitable" style="font-size: 14px; background: white;"
 +
|-
 +
|colspan="2"|Values for TKeyboardData.Modifiers
 +
|-
 +
|colspan="2"|&nbsp;
 +
|-
 +
| <code>KEYBOARD_LEFT_CTRL =  $00000001;</code>
 +
| The Left Control key is pressed
 +
|-
 +
| <code>KEYBOARD_LEFT_SHIFT =  $00000002;</code>
 +
| The Left Shift key is pressed
 +
|-
 +
| <code>KEYBOARD_LEFT_ALT =  $00000004;</code>
 +
| The Left Alt key is pressed
 +
|-
 +
| <code>KEYBOARD_LEFT_GUI =  $00000008;</code>
 +
| The Left GUI (or Windows) key is pressed
 +
|-
 +
| <code>KEYBOARD_RIGHT_CTRL =  $00000010;</code>
 +
| The Right Control key is pressed
 +
|-
 +
| <code>KEYBOARD_RIGHT_SHIFT =  $00000020;</code>
 +
| The Right Shift key is pressed
 +
|-
 +
| <code>KEYBOARD_RIGHT_ALT =  $00000040;</code>
 +
| The Right Alt key is pressed
 +
|-
 +
| <code>KEYBOARD_RIGHT_GUI =  $00000080;</code>
 +
| The Right GUI (or Windows) key is pressed
 +
|-
 +
| <code>KEYBOARD_NUM_LOCK =  $00000100;</code>
 +
| Num Lock is currently on
 +
|-
 +
| <code>KEYBOARD_CAPS_LOCK =  $00000200;</code>
 +
| Caps Lock is currently on
 +
|-
 +
| <code>KEYBOARD_SCROLL_LOCK =  $00000400;</code>
 +
| Scroll Lock is currently on
 +
|-
 +
| <code>KEYBOARD_COMPOSE =  $00000800;</code>
 +
| Compose is currently on
 +
|-
 +
| <code>KEYBOARD_KANA =  $00001000;</code>
 +
| Kana is currently on
 +
|-
 +
| <code>KEYBOARD_KEYUP =  $00002000;</code>
 +
| The key state changed to up
 +
|-
 +
| <code>KEYBOARD_KEYDOWN =  $00004000;</code>
 +
| The key state changed to down
 +
|-
 +
| <code>KEYBOARD_KEYREPEAT =  $00008000;</code>
 +
| The key is being repeated
 +
|-
 +
| <code>KEYBOARD_DEADKEY =  $00010000;</code
 +
| The key is a being handled as a deadkey}
 +
|-
 +
| <code>KEYBOARD_ALTGR =  $00020000;</code>
 +
| The AltGr key is pressed (Normally also Right Alt but may be Ctrl-Alt)
 +
|-
 +
|}
 +
</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;">'''Keyboard logging constants''' <code> KEYBOARD_LOG_* </code></div>
 +
<div class="mw-collapsible-content" style="text-align: left; padding-left: 5px;">
 +
{| class="wikitable" style="font-size: 14px; background: white;"
 +
|-
 +
| <code>KEYBOARD_LOG_LEVEL_DEBUG = LOG_LEVEL_DEBUG;</code>
 +
| Keyboard debugging messages
 +
|-
 +
| <code>KEYBOARD_LOG_LEVEL_INFO = LOG_LEVEL_INFO;</code>
 +
| Keyboard informational messages, such as a device being attached or detached
 +
|-
 +
| <code>KEYBOARD_LOG_LEVEL_ERROR = LOG_LEVEL_ERROR;</code>
 +
| Keyboard error messages
 +
|-
 +
| <code>KEYBOARD_LOG_LEVEL_NONE = LOG_LEVEL_NONE;</code>
 +
| No Keyboard messages
 +
|-
 +
|}
 +
</div></div>
 +
<br />
  
 
=== Type definitions ===
 
=== Type definitions ===

Revision as of 23:57, 27 November 2016

Return to Unit Reference


Description


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).

USB Keyboard Devices

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.

Constants



[Expand]
Keyboard specific constants KEYBOARD_NAME_*


[Expand]
Keyboard device type constants KEYBOARD_TYPE_*


[Expand]
Keyboard device state constants KEYBOARD_STATE_*


[Expand]
Keyboard device flag constants KEYBOARD_FLAG_*


[Expand]
Keyboard device control code constants KEYBOARD_CONTROL_*


[Expand]
Keyboard device LED constants KEYBOARD_LED_*


[Expand]
Keyboard buffer size constants KEYBOARD_BUFFER_*


[Expand]
Keyboard sampling rate constants KEYBOARD_REPEAT_*


[Expand]
Keyboard data definition constants KEYBOARD_*


[Expand]
Keyboard logging constants KEYBOARD_LOG_*


Type definitions


To be documented

Public variables


To be documented

Function declarations



Initialization functions

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


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:LongWord; var Argument2:LongWord):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


USB keyboard functions

[Expand]
function USBKeyboardDeviceRead(Keyboard:PKeyboardDevice; Buffer:Pointer; Size:LongWord; var Count:LongWord):LongWord;
Description: Implementation of KeyboardDeviceRead API for USB Keyboard


[Expand]
function USBKeyboardDeviceControl(Keyboard:PKeyboardDevice; Request:Integer; Argument1:LongWord; var Argument2:LongWord):LongWord;
Description: Implementation of KeyboardDeviceControl API for USB Keyboard


[Expand]
function USBKeyboardDriverBind(Device:PUSBDevice; Interrface:PUSBInterface):LongWord;
Description: Bind the Keyboard driver to a USB device if it is suitable


[Expand]
function USBKeyboardDriverUnbind(Device:PUSBDevice; Interrface:PUSBInterface):LongWord;
Description: Unbind the Keyboard driver from a USB device


[Expand]
procedure USBKeyboardReportWorker(Request:PUSBRequest);
Description: Called (by a Worker thread) to process a completed USB request from a USB keyboard IN interrupt endpoint


[Expand]
procedure USBKeyboardReportComplete(Request:PUSBRequest);
Description: Called when a USB request from a USB keyboard IN interrupt endpoint completes


Keyboard helper functions

[Expand]
function KeyboardGetCount:LongWord; inline;
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]
procedure KeyboardLog(Level:LongWord; Keyboard:PKeyboardDevice; const AText:String);
Description: To be documented


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


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


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


USB keyboard helper functions

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


[Expand]
function USBKeyboardCheckPressed(Keyboard:PUSBKeyboardDevice; ScanCode:Byte):Boolean;
Description: Check if the passed scan code has been pressed (True if not pressed in last report)


[Expand]
function USBKeyboardCheckRepeated(Keyboard:PUSBKeyboardDevice; ScanCode:Byte):Boolean;
Description: Check if the passed scan code was the last key pressed and if the repeat delay has expired


[Expand]
function USBKeyboardCheckReleased(Keyboard:PUSBKeyboardDevice; Report:PUSBKeyboardReport; ScanCode:Byte):Boolean;
Description: Check if the passed scan code has been released (True if not pressed in current report)


[Expand]
function USBKeyboardDeviceSetLEDs(Keyboard:PUSBKeyboardDevice; LEDs:Byte):LongWord;
Description: Set the state of the LEDs for a USB keyboard device


[Expand]
function USBKeyboardDeviceSetIdle(Keyboard:PUSBKeyboardDevice; Duration,ReportId:Byte):LongWord;
Description: Set the idle duration (Time between reports when no changes) for a USB keyboard device


[Expand]
function USBKeyboardDeviceSetProtocol(Keyboard:PUSBKeyboardDevice; Protocol:Byte):LongWord;
Description: Set the report protocol for a USB keyboard device


Return to Unit Reference