MCPcopy Create free account
hub / github.com/AutoHotkey/AutoHotkey / TextToHotkey

Method TextToHotkey

source/script_gui.cpp:9496–9557  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

9494
9495
9496WORD GuiType::TextToHotkey(LPTSTR aText)
9497// Returns a WORD (not a DWORD -- MSDN is wrong about that) compatible with the HKM_SETHOTKEY message:
9498// LOBYTE is the virtual key.
9499// HIBYTE is a set of modifiers:
9500// HOTKEYF_ALT ALT key
9501// HOTKEYF_CONTROL CONTROL key
9502// HOTKEYF_SHIFT SHIFT key
9503// HOTKEYF_EXT Extended key
9504{
9505 BYTE modifiers = 0; // Set default.
9506 for (bool done = false; *aText; ++aText)
9507 {
9508 switch (*aText)
9509 {
9510 case '!': modifiers |= HOTKEYF_ALT; break;
9511 case '^': modifiers |= HOTKEYF_CONTROL; break;
9512 case '+': modifiers |= HOTKEYF_SHIFT; break;
9513 default: done = true; // Some other character type, so it marks the end of the modifiers.
9514 }
9515 if (done) // This must be checked prior here otherwise the loop's ++aText will increment one too many.
9516 break;
9517 }
9518
9519 // For translating the virtual key below, the following notes apply:
9520 // The following extended keys are unlikely, and in any case don't have a non-extended counterpart,
9521 // so no special handling:
9522 // VK_CANCEL (Ctrl-break)
9523 // VK_SNAPSHOT (PrintScreen).
9524 //
9525 // These do not have a non-extended counterpart, i.e. their VK has only one possible scan code:
9526 // VK_DIVIDE (NumpadDivide/slash)
9527 // VK_NUMLOCK
9528 //
9529 // All of the following are handled properly via the scan code logic below:
9530 // VK_INSERT
9531 // VK_PRIOR
9532 // VK_NEXT
9533 // VK_HOME
9534 // VK_END
9535 // VK_UP
9536 // VK_DOWN
9537 // VK_LEFT
9538 // VK_RIGHT
9539 //
9540 // Same note as above but these cannot be typed by the user, only programmatically inserted via
9541 // initial value of "Gui Add" or via "GuiControl,, MyHotkey, ^Delete":
9542 // VK_DELETE
9543 // VK_RETURN
9544 // Note: NumpadEnter (not Enter) is extended, unlike Home/End/Pgup/PgDn/Arrows, which are
9545 // NON-extended on the keypad.
9546
9547 BYTE vk = TextToVK(aText);
9548 if (!vk)
9549 return 0; // Indicate total failure because a hotkey control can't contain just modifiers without a VK.
9550 // Find out if the HOTKEYF_EXT flag should be set.
9551 sc_type sc = TextToSC(aText); // Better than vk_to_sc() since that has both an primary and secondary scan codes to choose from.
9552 if (!sc) // Since not found above, default to the primary scan code.
9553 sc = vk_to_sc(vk);

Callers

nothing calls this directly

Calls 3

TextToVKFunction · 0.85
TextToSCFunction · 0.85
vk_to_scFunction · 0.85

Tested by

no test coverage detected