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

Function SetModifierAsPrefix

source/hook.cpp:3335–3408  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

3333
3334
3335void SetModifierAsPrefix(vk_type aVK, sc_type aSC, bool aAlwaysSetAsPrefix = false)
3336// The caller has already ensured that vk and/or sc is a modifier such as VK_CONTROL.
3337{
3338 if (aVK)
3339 {
3340 switch (aVK)
3341 {
3342 case VK_MENU:
3343 case VK_SHIFT:
3344 case VK_CONTROL:
3345 // Since the user is configuring both the left and right counterparts of a key to perform a suffix action,
3346 // it seems best to always consider those keys to be prefixes so that their suffix action will only fire
3347 // when the key is released. That way, those keys can still be used as normal modifiers.
3348 // UPDATE for v1.0.29: But don't do it if there is a corresponding key-up hotkey for this neutral
3349 // modifier, which allows a remap such as the following to succeed:
3350 // Control::Send {LWin down}
3351 // Control up::Send {LWin up}
3352 if (!aAlwaysSetAsPrefix)
3353 {
3354 for (int i = 0; i < Hotkey::sHotkeyCount; ++i)
3355 {
3356 Hotkey &h = *Hotkey::shk[i]; // For performance and convenience.
3357 if (h.mVK == aVK && h.mKeyUp && !h.mModifiersConsolidatedLR && !h.mModifierVK && !h.mModifierSC
3358 && !h.IsCompletelyDisabled())
3359 return; // Since caller didn't specify aAlwaysSetAsPrefix==true, don't make this key a prefix.
3360 }
3361 }
3362 switch (aVK)
3363 {
3364 case VK_MENU:
3365 kvk[VK_MENU].used_as_prefix = PREFIX_FORCED;
3366 kvk[VK_LMENU].used_as_prefix = PREFIX_FORCED;
3367 kvk[VK_RMENU].used_as_prefix = PREFIX_FORCED;
3368 ksc[SC_LALT].used_as_prefix = PREFIX_FORCED;
3369 ksc[SC_RALT].used_as_prefix = PREFIX_FORCED;
3370 break;
3371 case VK_SHIFT:
3372 kvk[VK_SHIFT].used_as_prefix = PREFIX_FORCED;
3373 kvk[VK_LSHIFT].used_as_prefix = PREFIX_FORCED;
3374 kvk[VK_RSHIFT].used_as_prefix = PREFIX_FORCED;
3375 ksc[SC_LSHIFT].used_as_prefix = PREFIX_FORCED;
3376 ksc[SC_RSHIFT].used_as_prefix = PREFIX_FORCED;
3377 break;
3378 case VK_CONTROL:
3379 kvk[VK_CONTROL].used_as_prefix = PREFIX_FORCED;
3380 kvk[VK_LCONTROL].used_as_prefix = PREFIX_FORCED;
3381 kvk[VK_RCONTROL].used_as_prefix = PREFIX_FORCED;
3382 ksc[SC_LCONTROL].used_as_prefix = PREFIX_FORCED;
3383 ksc[SC_RCONTROL].used_as_prefix = PREFIX_FORCED;
3384 break;
3385 }
3386 break;
3387
3388 default: // vk is a left/right modifier key such as VK_LCONTROL or VK_LWIN:
3389 if (aAlwaysSetAsPrefix)
3390 kvk[aVK].used_as_prefix = PREFIX_ACTUAL;
3391 else
3392 if (Hotkey::FindHotkeyContainingModLR(kvk[aVK].as_modifiersLR)) // Fixed for v1.0.35.13 (used to be aSC vs. aVK).

Callers 1

ChangeHookStateFunction · 0.85

Calls 1

IsCompletelyDisabledMethod · 0.80

Tested by

no test coverage detected