Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Incrementing A Number In Loop?
#3
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
Code:
Copy      Help
;// 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
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)


Messages In This Thread
Incrementing A Number In Loop? - by mku - 04-07-2022, 11:44 AM
RE: Incrementing A Number In Loop? - by stupomer - 04-07-2022, 12:53 PM
RE: Incrementing A Number In Loop? - by ScottF - 04-28-2022, 11:37 AM

Forum Jump:


Users browsing this thread: 1 Guest(s)