THotKey
Source: source/classes/thotkey.prg
Inherits from: TControl
THotKey wraps the Win32 hot key common control, allowing the user to press a keyboard combination (e.g., Ctrl+Alt+F5) which is captured and stored as a virtual-key code and modifier mask. It is commonly used in configuration dialogs where users define custom keyboard shortcuts.
Key DATA Members
| DATA | Type | Description |
|---|---|---|
nVirtKey | Numeric | Virtual-key code of the selected key (e.g., VK_F5) |
nModifiers | Numeric | Bitmask of modifier keys: HOTKEYF_SHIFT, HOTKEYF_CONTROL, HOTKEYF_ALT |
Methods
| Method | Description |
|---|---|
New( nRow, nCol, oWnd, nVK, nMod ) | Create a new hotkey input control |
SetHotKey( nVK, nMod ) | Programmatically set the hotkey to nVK with modifiers nMod |
GetHotKey() | Return an array { nVirtKey, nModifiers } of the current hotkey |
GetKeyName() | Return a human-readable string such as "Ctrl+Alt+F5" |
SetRules( nInv, nDef ) | Set invalid key combinations and default override behavior |
Example: Hotkey Picker with Change Callback
#include "FiveWin.ch"
function Main()
local oWnd, oHot, nVK := VK_F5, nMod := HOTKEYF_CONTROL + HOTKEYF_ALT
DEFINE WINDOW oWnd TITLE "Hotkey Demo" SIZE 400, 150
@ 40, 20 HOTKEY oHot ;
SIZE 120, 25 OF oWnd ;
ACTION MsgInfo( "Hotkey: " + oHot:GetKeyName() )
oHot:SetHotKey( nVK, nMod )
ACTIVATE WINDOW oWnd CENTERED
return nil
Notes
- THotKey captures the key combination when the control has focus and the user presses a modifier+key chord. The combination is displayed in the control.
- Modifier constants:
HOTKEYF_SHIFT(1),HOTKEYF_CONTROL(2),HOTKEYF_ALT(4). Combine with+for multi-modifier hotkeys. GetKeyName()returns a localized string suitable for display in menus or configuration lists.- Use
SetRules()to specify which key combinations are invalid.nInvis a mask of invalid modifiers andnDefspecifies the default modifier to use when the user types an invalid combination.