Thanks
boiler for the questions - you got me thinking in a right direction: I have just realized that Hotkey function turns off not only
Hotkey function created hotkeys but
hotkey labels as well! It seems I have missed that in documentation. So it's obvious why we would see only one MsgBox after multiple key presses, as this code illustrates:
Code: Select all
#SingleInstance Force
Gui, Add, Text,, Press F1 button for message
Gui, Show, w200 h150
Return
F1::
MsgBox How many times will you see me?
Hotkey F1, , Off
Return
ESC::ExitApp
Furthermore it seems that by creating a hotkey by a function call (Hotkey) within a hotkey label (F1::) we simply re-label the hotkey - as demonstrated here:
Code: Select all
#SingleInstance Force
Gui, Add, Text,, Release F1 button for message
Gui, Show, w200 h150
Return
F1::
Hotkey F1, _RelabeledF1hotkey, On
MsgBox Message from the 1st hotkey label
Return
_RelabeledF1hotkey:
MsgBox Message from the 2nd hotkey label
Return
ESC::ExitApp
So to answer the initial question - a "key-press for a hotkey of a key-release" simply has to be seen as a hotkey relabeling, without turning off the hotkey itself. That's when we would see multiple button presses to invoke multiple messages. Here's the fix:
Code: Select all
#SingleInstance Force
Gui, Add, Text,, Release F1 button for message
Gui, Show, w200 h150
Return
F1::
Hotkey F1, __Message, On
Return
__Message:
KeyWait F1
;; Hotkey F1, __Message, Off
MsgBox The button has been released
Return
ESC::ExitApp