11-02-2018, 07:02 AM
Macro Macro35
Function IsHotkey
;Waits for hotkey Ctrl+B in a loop. On hotkey calls function sub.Func1.
;Then sub.Func1 works in a loop. When the hotkey pressed again, it returns, and the macro waits for hotkey again.
;Press Pause to end the macro.
__RegisterHotKey hk2.Register(0 2 MOD_CONTROL 'B') ;;Ctrl+B
rep() if(IsHotkey(1)) sub.Func1
#sub Func1
out "enter Func1"
rep
,if(IsHotkey) out "leave Func1"; ret
,;work
,;work
,;work
Function IsHotkey
;/
function# [waitForHotkey]
;When received a registered hotkey message (WM_HOTKEY), returns the hotkey id.
;Can wait for message or not.
;waitForHotkey - whether to wait for hotkey message.
;;;If 0 or omitted, does not wait. If message received, returns the hotkey id, else returns 0.
;;;If not 0, waits for message and returns the hotkey id when received.
;See also: <__RegisterHotKey>
MSG m
rep
,if waitForHotkey
,,if(GetMessage(&m 0 0 0)<1) end
,else
,,if(!PeekMessage(&m 0 0 0 PM_REMOVE)) ret
,,if(m.message=WM_QUIT) end
,
,if(m.message=WM_HOTKEY) ret m.wParam
,TranslateMessage &m
,DispatchMessage &m