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

DATATypeDescription
nVirtKeyNumericVirtual-key code of the selected key (e.g., VK_F5)
nModifiersNumericBitmask of modifier keys: HOTKEYF_SHIFT, HOTKEYF_CONTROL, HOTKEYF_ALT

Methods

MethodDescription
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

See Also