Hello again! The main purpose of the callback is to take a snapshot of sorts, right? We need to remember which specific hotkey called the function.
Because it's global, we can't necessarily depend on
A_ThisHotkey for this purpose. Other threads might alter the value before we use it.
Consider the following example derived from your code:
Run the code, then press RShift followed quickly by LShift.
Code: Select all
Hotkey( "RShift", (ThisHotKey) => MyFuncR(ThisHotKey) )
Hotkey( "LShift", (ThisHotKey) => MyFuncL(ThisHotKey) )
MyFuncR(ThisHotKey)
{
sleep 3000
if( A_ThisHotkey != ThisHotKey )
throw Exception("Confusion!")
}
MyFuncL(ThisHotKey)
{
if( A_ThisHotkey != ThisHotKey )
throw Exception("Confusion!")
}
By the time the RShift thread reaches the if-statement, the LShift thread has already overwritten the value of A_ThisHotKey and we get a mismatch.
This is one of the reasons many people avoid using globals when they can.