Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Registering hot keys, waiting for hotkeys
#5
Macro Macro35
Code:
Copy      Help
;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
Code:
Copy      Help
;/
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


Messages In This Thread

Forum Jump:


Users browsing this thread: 1 Guest(s)