Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Set end-thread hotkey
#1
Function SetEndThreadHotkey
Code:
Copy      Help
;/

function $hotkey

;Sets a hotkey to end current thread (running macro or function).

;hotkey - a single key without modifiers (Ctrl etc), specified as QM key code like with <help>key</help> and QM keyboard triggers.

;EXAMPLE
;SetEndThreadHotkey "F8"
;;macro
;rep
,;out 1
,;wait 1


int mod vk; if(!TO_HotkeyFromQmKeys(hotkey mod vk)) end "invalid hotkey string"
if(mod) end "modifier keys not supported"

QMTHREAD qt; GetQmThreadInfo(0 qt)
mac "sub.Thread" "" qt.threadhandle vk


#sub Thread
function ht vk

int- __ht82657(ht) __vk82657(vk)

int hh=SetWindowsHookEx(WH_KEYBOARD_LL &sub.Hook_WH_KEYBOARD_LL _hinst 0)
opt waitmsg 1
wait 0 H ht
UnhookWindowsHookEx hh


#sub Hook_WH_KEYBOARD_LL
function# nCode message KBDLLHOOKSTRUCT&k
if(nCode<0) goto gNext
if(k.flags&(LLKHF_UP|LLKHF_INJECTED)) goto gNext

int- __ht82657 __vk82657
if k.vkCode=__vk82657
,EndThread "" __ht82657
,ret 1

;gNext
ret CallNextHookEx(0 nCode message &k)

example
Macro Macro2718
Code:
Copy      Help
;add this line before the macro. Change the hotkey.
SetEndThreadHotkey "F12"

;your macro (example)
rep
,out 1
,wait 1

This can be useful where the common hotkey (Pause) cannot be used:
To end a non-macro thread (function etc).
When the macro has property "run simultaneously".
When you want to use a separate end-thread hotkey for some macros.
This also can be used to end .exe macros, but probably it's better to set hotkey in the "Make exe" dialog.
#2
Why do I use the function of SetEndThreadHotkey, one computer(win10) can run, but the others(win10, win7) can't run?
Appreciate your advice.
#3
Need more info about "can't run". Does it show an error message?
#4
QM doesn't show any error message.
I run the example as below

Macro Macro12
Code:
Copy      Help
SetEndThreadHotkey "F8"
;macro
rep
,out 1
,wait 1

One computer can run successfully, and Running item's(QM) Threads show "SetEndThreadHotkey:Thread"
The other computers can't run successfully, it can run marco rep, but don't show "SetEndThreadHotkey:Thread".
#5
And F8 does not work? Maybe don't show "SetEndThreadHotkey:Thread" because it is hidden. It depends on QM settings. Look in Options / General / Show hidden Running items.
#6
Thanks, it can't run early, but it can run now...
and thanks for your information about QM settings.
#7
Gintaras Wrote:And F8 does not work? Maybe don't show "SetEndThreadHotkey:Thread" because it is hidden. It depends on QM settings. Look in Options / General / Show hidden Running items.

What does pressing F8 supposed to do?


Forum Jump:


Users browsing this thread: 1 Guest(s)