I wrote this simple AHK script, it's working. But rightclick systray icon- suspend/pause, it just still keep working. Is it because of something in my code? or about win7 x64?
#Persistent
return
OnClipboardChange:
WinGetActiveTitle, OutputVar
IfWinExist, collect.doc
{
WinActivate ; use the window found above
send,^v
send,{Enter}
winactivate,%Outputvar%
}
else
tooltip,need collect doc,400,400
Sleep 100
return
Both Pause and Suspend are not meant to block automatically called subroutines like OnClipboardChange
or GuiClose
. Pause
merely blocks the current thread, which means that every newly created thread will still run, and a clipboard change does create a new thread. Ergo, Pause
can't block it.
In such cases, you need to implement an own piece of logic within the "event subroutine" that checks some kind of state.
Going with your premise to make the functionality depend on the paused state, a fairly easy way would be to check for the built-in A_IsPaused
:
OnClipboardChange:
if(A_IsPaused) {
return
}
msgbox, 'sup?
return
There are certainly many ways to implement this. You could also define your own hotkey to activate/deactivate/toggle a custom state.
P.S:
Activating a window only to paste some text seems a bit unnecessary and bothersome to me; have a look at the Control
commands (e.g. Control, EditPaste) or access Word via COM. Depending on what you do, I believe directly writing to a text file and/or in-memory storage might be a better alternative to a running Word instance anyway.
P.P.S:
You might want to be careful with such a negligent clipboard logger. I assume you don't want every kind of data (e.g. passwords) showing up there.