Menu ▾ ▴

#88 THotkey_SetHotkey/THotkey_GetHotkey: key tables with entries that do nothing, a list kept twice, and SetHotkey changes the control's rules for invalid keys

unread
nobody
2026-10-19
2026-10-19
No

Found by a code review of [bugs:#87], in code that fix did not touch (u_dzVclUtils).

1. Table entries that do nothing or name keys no keyboard sends. Measured with MapVirtualKey and GetKeyNameText, the name being what the scan code gives with and without the extended flag (one machine, en-GB):

Key Scan code Without extended flag With extended flag
VK_LEFT ($25) $4B NUM 4 LEFT
VK_NUMLOCK ($90) $45 Pause Num Lock
VK_DIVIDE ($6F) $35 / NUM DIVIDE
VK_MULTIPLY ($6A) $37 NUMMULT Prnt Scrn
VK_PAUSE ($13) 0 (none) (none)
VK_PRINT ($2A) 0 (none) (none)
VK_SNAPSHOT ($2C) $54 (none) <00>
  • VK_PRINT is not what the Print Screen key sends, that is VK_SNAPSHOT, which is in neither table. VK_PRINT and VK_PAUSE have no scan code, so setting hkExt for them in THotkey_SetHotkey changes nothing.
  • VK_NUMLOCK shares its scan code with Pause, like the arrow keys share theirs with the keypad digits, but both tables map it to itself.
  • With the fix for bugs #87 the last four entries of EXT_KEYS and STD_KEYS (VK_NUMLOCK, VK_PAUSE, VK_PRINT, VK_DIVIDE) are the same key in both tables, so THotkey_GetHotkey can only replace them with themselves.

What the hot key control itself shows for these keys, and what it stores when they are pressed, is not measured.

2. The list of extended keys exists twice. THotkey_SetHotkey has its own Key in [VK_LEFT, ..., VK_DIVIDE] set next to EXT_KEYS. A key added to or corrected in one but not the other breaks the round trip SetHotkey / GetHotkey.

3. THotkey_SetHotkey changes the control's rules for invalid key combinations. It adds or removes hkExt through the Modifiers property, and TCustomHotKey.SetModifiers (Vcl.ComCtrls, Delphi 12) sends HKM_SETRULES with the new modifiers as the fallback for invalid combinations, before it sends HKM_SETHOTKEY. After THotkey_SetHotkey(hk, Ctrl+Left) the fallback is Ctrl + extended instead of the component's Modifiers default [hkAlt]. Read in the source, the effect on what a user then types is not measured.

Expected: tables that only hold keys the control can show and that have a twin, one list of extended keys, and setting the extended flag without changing the rules (e.g. HKM_SETHOTKEY with HOTKEYF_EXT directly).

Related

Bug Reports: #87

Discussion


Log in to post a comment.