Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Registering hot keys, waiting for hotkeys
#1
Examples.

Function dialog_hotkeys
Code:
Copy      Help
\Dialog_Editor

str dd=
;BEGIN DIALOG
;0 "" 0x90C80AC8 0x0 0 0 223 135 "Dialog"
;1 Button 0x54030001 0x4 120 116 48 14 "OK"
;2 Button 0x54030000 0x4 170 116 48 14 "Cancel"
;END DIALOG
;DIALOG EDITOR: "" 0x2030506 "*" "" "" ""

if(!ShowDialog(dd &sub.DlgProc 0)) ret


#sub DlgProc
function# hDlg message wParam lParam
__RegisterHotKey- t_hk1 t_hk2
sel message
,case WM_INITDIALOG
,t_hk1.Register(hDlg 1 MOD_CONTROL|MOD_SHIFT VK_F5) ;;Ctrl+Shift+F5
,t_hk2.Register(hDlg 2 MOD_ALT|MOD_WIN 'Q') ;;Alt+Win+Q
,
,case WM_HOTKEY
,sel wParam
,,case 1 out "Ctrl+Shift+F5"
,,case 2 out "Alt+Win+Q"
,
,case WM_DESTROY
,case WM_COMMAND goto messages2
ret
;messages2
sel wParam
,case IDOK
,case IDCANCEL
ret 1

Macro __RegisterHotKey example
Code:
Copy      Help
;Shows how to use __RegisterHotKey to use hotkeys in a windowless thread.
;This should be function, not macro, because runs all the time.

__RegisterHotKey hk1.Register(0 1 MOD_CONTROL|MOD_SHIFT VK_F5)
;also can register more hotkeys, for example
__RegisterHotKey hk2.Register(0 2 MOD_CONTROL 'B')
;...

MSG m
rep
,if(GetMessage(&m 0 0 0)<1) break
,sel m.message
,,case WM_HOTKEY
,,sel m.wParam
,,,case 1 ;;Ctrl+Shift+F5 pressed
,,,mac "Function_that_does_something_on_Ctrl_Shift_F5"
,,,
,,,case 2
,,,out "Ctrl+B"
,,,
,,,;...
,,,
,DispatchMessage &m
#2
;register hotkey Ctrl+K with id 70

sorry, but for what could be id 70 be used?
pi
#3
It is wParam in WM_HOTKEY message. I replaced the old code. Now QM has class __RegisterHotKey, delete class CRegisterHotKey if you have it.
#4
Hey Gintaras… I've been trying to implement something like this in a long macro I wrote, but for some reason I doesn't seem to work.  What I'd like is to have a hotkey assigned at the beginning of the macro, if that hotkey is pressed it will run a function until the hotkey is pressed again, thus causing the macro to pause.  When the hotkey is pressed again it continues where it left off.  I'm not quite sure if I'm explaining this properly, but so far the examples you've given althou they work for the example don't quite work in anything else.  So, let's say I've got a long macro that takes 10 minutes to run.  As it's running (say 3 minutes into the macro) I press CTRL-SCROLL LOCK and it will pause the running macro by going to a looping function that sits there and waits for me to look for CTRL-SCROLL LOCK or ESC (if ESCAPE is pressed the macro ends).  If it sees the CTRL-SCROLL LOCK button pressed, it exists the function and returns to the spot in the macro where it was "paused" from.  Now I'm not talking about a thread pause, I'm talking about a simple old BASIC command like "ON KEY GOSUB FUNCTION" and "RETURN".  That would effectively pause any running macro and allow it to resume if it's pressed again or ended if the ESCAPE key is pressed.  Make sense?
#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
#6
Nope... Still not working... Not sure what's going on here! Maybe it's the new Windows 10 configuration or virus shield.


Forum Jump:


Users browsing this thread: 1 Guest(s)