I am facing a subtle problem, on Autohotkey 1.1.36. Please see this Esc1.ahk
:
~Esc & 1:: Esc1()
Esc1()
{
static s_count := 0
s_count++
tooltip, % "Esc1 #" s_count
}
The purpose of this script is: When I press combo-key Esc & 1, a tooltip appears indicating that combo-key is triggered.
Now do the following operation:
- Press down Esc when Notepad (or any text editor, EmEditor in my own case) on the host machine is the active window.
- Mouse click inside a VMware Workstation VM window.
- Release Esc.
- Mouse click EmEditor, making it host-machine active window again.
- Press key 1, one or more times.
Now, surprising thing happens, tooltip Esc1 #2
, Esc1 #3
etc appears, and the letter '1' does NOT get typed into the text editor -- although we have already released Esc.
We can easily imagine what has happened: When we deliberately release Esc not from the host machine but from inside the VM, Autohotkey engine running on the host machine does not get Esc's KEYUP event, so in step 5 above, Autohotkey still thinks the Esc key is being pressed down. This weird behavior persists until we press and release Esc again, from a non-VM window.
So my question is: Is it possible to detect this exceptional situation from our own AHK script, and, what AHK statements can be used to recover from this? By saying "exceptional", I mean: when the physical key-state is actually UP, while Autohotkey engine thinks it is DOWN.
When this mismatch symptom happens, GetKeyState("Esc", "P")
returns 1, which means "key pressed", but the physical key state is released. No luck yet.