Posts: 1
Threads: 1
Joined: Apr 2022
I've created a macros that successfully targets an already-opened app, then pauses for one minute (60 seconds) before what I'm hoping is a loop to occur:
int w1=act(win("Untitled - Notepad" "Notepad"))
lef 167 72 w1 1 ;;editable text
'"word0001" ;; "word0001"
wait 60
Can anyone enlighten me on how to not only loop the script , but also make "0001" increase by one on each loop until say "9999"? Much appreciated.
Posts: 1,006
Threads: 330
Joined: Mar 2007
Macro
Macro33
int w=win("Untitled - Notepad" "Notepad")
act id(15 w) ;;editable text 'Text Editor'
str sBlock
for _i 1 10000
,_s.format("%04i" _i)
,key F"word{_s}[]";;[] adds new line; remove if you don't want
above slow and dangerous unless you block key and mouse input which could change focus - see
BlockInput2, though this can also be tricky and sometimes dangerous to use.
This better:
str sColl
for _i 1 10000
,_s.format("%04i" _i)
,sColl.addline(F"word{_s}")
int w=win("Untitled - Notepad" "Notepad")
sColl.setwintext(id(15 w)) ;;editable text 'Text Editor'
tip: learn QM faster and more easily by using the 'wizards' in the toolbar, especially useful are the ones that put arrows on (though all eventually become lifesavers! thanks Gintaras!!!!)
Posts: 62
Threads: 22
Joined: Jul 2017
Hope the this helps. This is probably easier understand, but longer code.
The function (SetEndThreadHotkey), will allow you to terminate the thread with any Function key. default "F12"
Function
Increment_Num_Notepad
;// Increment_Num_Notepad \\
;;;;;2022-04-28 Thursday - 07.26.26
int i=1
str s s1 sw
str wd = "word"
SetEndThreadHotkey "F12" ;; «--‹‹ ≡KILL SWITCH≡ --- Change to any "Fxx" Function Key.
;;;;; Loop
if i < 9
,s1 = "000"
if i > 9
,s1 = "00"
if i > 99
,s1 = "0"
if i > 9999
,goto Bottom
s=i ;; <--- Convert incremented number to string, for output in notepad.
sw.from(wd s1 s) ;; <--- Combine: "word" + "0xx" + "x" = Eg. word+000+1
int w1=act(win("Untitled - Notepad" "Notepad")) ;; <--- This will activate Notepad evry loop.
;;;--> lef 167 72 w1 1 ;;editable text ;; <--- Remarked so won't steal the mouse.
outp (sw); 'Y ;; <--- Output string in Notepad and Enter to new line.
wait 60 ;; <--- Wait a Minute.
i + 1 ;; <--- Increment number x1.
goto Loop ;; <--- Start Loop again.
;;;;; Bottom
;End Function
Function
SetEndThreadHotkey
;/
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)