swapping ctrl and alt keys --- bug with alt-tabbing Topic is solved

Report problems with documented functionality
priestleylattice
Posts: 1
Joined: 24 Jun 2017, 05:35

swapping ctrl and alt keys --- bug with alt-tabbing

24 Jun 2017, 05:52

I have the following in a ahk script to switch ctrl and alt and map capslock to alt.

Code: Select all

SetCapsLockState, AlwaysOff

LCtrl::Alt
LAlt::Ctrl
CapsLock::Alt
If I press CapsLock+Tab (alt-tabbing) to switch from a window, say chrome (this doesn't matter; the bug is replicated for many choices here), to keepass, and press Alt (sending ctrl), for example as a combination Alt+C (to copy) or even by itself, the following sequence happens
  • CapsLock+Tab (keepass pops up)
    Alt (sends ctrl; nothing happens)
    CapsLock+Tab (chrome pops up)
    CapsLock+Tab (keepass pops up)
    Alt (alt key is sent; the "file" menu is highlighted)
    CapsLock+Tab (chrome pops up)
If I repeat this sequence, the same exact behavior occurs.

The annoying thing about this is that in practice when I want to switch to keepass and copy a password by pressing Alt+C (sending Ctrl+C), the Alt grabs the "file" menu instead.

This bug also occurs when switching to Notepad++ with CapsLock+Tab (sending alt+tab).
lexikos
Posts: 9583
Joined: 30 Sep 2013, 04:07
Contact:

Re: swapping ctrl and alt keys --- bug with alt-tabbing  Topic is solved

15 Jul 2017, 22:02

Fixed in v1.1.26.01.

There was a simpler way to reproduce it:
  • Test with an Alt-blocking hotkey such as LAlt::return or LAlt::LCtrl.
  • Open Notepad and alt-tab away using the other Alt key or a remapping such as LCtrl::LAlt.
  • Reactivate Notepad.
  • Press LAlt and the menus are activated once, even though LAlt is supposed to be blocked.
This is related to two Windows bugs/quirks:
  1. Alt-tabbing away from a window (or holding Alt and clicking/activating a different window) usually leaves it in a confused state, where (after releasing Alt and reactivating the window):
    • The menu's keyboard accelerators are still visible, even if they're usually only visible while holding Alt.
    • Pressing a letter does not activate the menu (good).
    • Pressing and releasing Alt does not activate the menu, but instead just hides the keyboard accelerators (bad).
    • Releasing Alt (either the other physical Alt key, or by sending an Alt-up event) activates the menu, where normally it would do nothing.
  2. Blocking an Alt key-down event does not prevent the system from processing menu activation hotkeys such as Alt+F (for File).
I can reproduce #1 with Notepad on Windows 10 (without any scripts running):
  • Open Notepad: the keyboard accelerators are not visible.
  • Deactivate Notepad.
  • Hold Alt, reactivate Notepad and release Alt: nothing happens (normal behaviour).
  • Alt-tab away from Notepad (slowly).
    OR: Hold Alt and click on another window to deactivate Notepad.
  • ... release Alt, do other things, go make a coffee, etc. ...
  • Hold Alt, reactivate Notepad and release Alt: the menu activates (abnormal).
  • Press Alt to reset/deactivate the menus.
  • Alt-tab away from Notepad (slowly).
  • Reactivate Notepad: the keyboard accelerators are visible (abnormal).
  • Press Alt: the keyboard accelerators hide and the menu does not activate (abnormal).
The workaround for #2 is to send an Alt-up event when an Alt-down event is being blocked, as commented in the source code:

Code: Select all

// Since this is a hotkey that fires on ALT-DOWN and it's a normal (suppressed) hotkey,
// send an up-event to "turn off" the OS's low-level handling for the alt key with
// respect to having it modify keypresses.  For example, the following hotkeys would
// fail to work properly without this workaround because the OS apparently sees that
// the ALT key is physically down even though it is not logically down:
// RAlt::Send f  ; Actually triggers !f, which activates the FILE menu if the active window has one.
// RAlt::Send {PgDn}  ; Fails to work because ALT-PgDn usually does nothing.
However, in v1.1.26.00 and earlier, the workaround triggered problem #1.

v1.1.26.01 fixes issues caused by the workaround in two ways:
  • Send Alt-up but then block it via the keyboard hook, so the event never reaches the active window. This is apparently sufficient to counteract the previously blocked Alt key-down.
  • #2 appears to have been fixed in Windows 10 (tested on 10.0.15063), so the workaround is applied only on Windows 8.1 and earlier.

Return to “Bug Reports”

Who is online

Users browsing this forum: No registered users and 14 guests