OK, I may have a bug for you here.
Run the following script which watches for you to press a Hot Key... the ALT key and the ` key (the key below the ESC key) simultaneously.
In addition, after the key combo has been pressed, it also checks to MAKE SURE that you have released both of those keys... before initiating an action.
If you run the code below, you should find it solid... in that, once you hold down ALT and also hold down `... then as long as you KEEP holding down ALT, the Action will NOT TRIGGER... it will wait until you have released the ALT key.
Code: Select all
//Values below used for Hot Keys
//VK_SHIFT?(16) SHIFT key
Let>VK_SHIFT=16
//VK_CONTROL?(17) CTRL key
Let>VK_CONTROL=17
//VK_MENU?(18) ALT key
Let>VK_MENU=18
//VK_OEM_3?(192)
//Used for miscellaneous characters; it can vary by keyboard.
//Windows 2000/XP: For the US standard keyboard, the '`~' key
Let>VK_OEM_3=192
//app spends most of its time in this loop... waiting for something to happen
Label>Loop
Wait>0.01
//use GetKeyState for hot key instead of "RegisterHotKey" as no debounce problem
//result values will be as follows:
//SHIFT(VK_SHIFT) or ALT(VK_MENU) or CTRL(VK_CONTROL) down: 65408 or 65409 up: 0 or 1
//so key is down if result>1
//and key is up if result<2
//Check if '`~' key is down
LibFunc>user32,GetKeyState,result,VK_OEM_3
If>result<0
//Yes '`~' key is down so now check if ALT(VK_MENU) is down
LibFunc>user32,GetKeyState,result,VK_MENU
If>result>1
//yes ALT was down so at this point we know hot key was pressed
//ensure VK_USER_CHOSEN_HOTKEY is up first
Label>wait_for_VK_USER_CHOSEN_HOTKEY_to_be_up
LibFunc>user32,GetKeyState,result,VK_OEM_3
If>result<0,wait_for_VK_USER_CHOSEN_HOTKEY_to_be_up
//finally wait for ALT key to be up
Label>wait_for_ALT_to_be_up
LibFunc>user32,GetKeyState,result,VK_MENU
//following line does not work consistantly
//If>result>1,wait_for_ALT_to_be_up
//following line does not work consistantly
//If>result>65407,wait_for_ALT_to_be_up
//Only the following line works consistantly
If>{(%result%<>0) AND (%result%<>1)},wait_for_ALT_to_be_up
//so now initiate Action
GoSub>Action
EndIf
EndIf
Goto>Loop
SRT>Action
MDL>You pressed and released ALT + `
Exit>0
END>Action
//If>result>1,wait_for_ALT_to_be_up
//following line does not work consustantly
//If>result>65407,wait_for_ALT_to_be_up
//Only the following line works consistantly
If>{(%result%0) AND (%result%1)},wait_for_ALT_to_be_up
While I am glad the green line above does work... I don't understand why the red lines do not.
Please comment out the green line and uncomment one of the red lines and test it.
You can press the Hot Key... and even though you KEEP holding the ALT key down... if you alternately press and release the ` key... you can get it to trigger the Action... without ever releasing the ALT key.
This drove me insane until I found a solution... and I have been meaning to post about this for a long time... so here it is.
Why does it behave like this Marcus? Is there some kind of edge case bug with the If> statement?