Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
key trigger
#2
simple example
Macro Macro1
Code:
Copy      Help
atend sub.cleanup   ;; calls subfunction  to make sure trigger is disabled when macro1 is not running
dis- "Function1"  ;; enables trigger when macro1 starts
;just a simple repeating function that outputs a number;;
int x
rep
,out x
,x+1
,1

#sub cleanup
;;checks to makes sure trigger is disabled when Macro1 ends
int i = qmitem("Function1")
if(!dis(i))
,dis+ "Function1"
Function Function1
Trigger w     Help - how to add the trigger to the macro
Code:
Copy      Help
int i = qmitem("Function1")
if(!dis(i))
,dis+ "Function1";; disables trigger so function cannot be run while paused
out "Paused"
ThreadPauseResume "Macro1" 0
10 ;;change number here to adjust wait time
ThreadPauseResume "Macro1" 1
out "Resumed"
if(dis(i))
,dis- "Function1";;enables trigger so function can run again if needed

Function ThreadPauseResume
Code:
Copy      Help
;/
function $threadName flags ;;flags: 0 pause, 1 resume

;Pauses (suspends) or resumes a QM thread.

;threadName - <help #IDP_THREADS>thread</help> name.
;;;This function pauses/resumes all threads of threadName.
;;;If "", pauses/resumes all macro threads (except self), but not function, menu etc threads.

;REMARKS
;Call this function from another thread.
;You must always resume paused threads. QM does not know about paused threads and cannot end them correctly.
;If you pause a thread several times (when it is already paused), you must resume it the same number of times (or more, it is safe). It will remain paused if you resume it just once.

;EXAMPLE
;ThreadPauseResume "Function293" 0
;mes "resume"
;ThreadPauseResume "Function293" 1


int h i n m=empty(threadName)
n=EnumQmThreads(0 0 0 threadName); if(!n) ret
ARRAY(QMTHREAD) a.create(n)
EnumQmThreads &a[0] n 0 threadName
for i 0 a.len
,if(a[i].threadid=GetCurrentThreadId) continue
,if m
,,QMITEM q; qmitem(a[i].qmitemid 0 q)
,,if(q.itype) continue
,h=a[i].threadhandle
,if(flags&1) ResumeThread h
,else SuspendThread h


Messages In This Thread

Forum Jump:


Users browsing this thread: 1 Guest(s)