Autohotkey Pause a Script for 5 Seconds Then Continue
Hi,
I would like to know how to ''Pause' (not suspend) my ahk script for X seconds, the problem I have is that if I use pause then the 'Sleep' command doesn't work, I have tried with SetTimer also and toggle, but maybe Im not thinking clearly
It would be something like this:
^w::
Pause, on
Sleep 5000
Pause, off
return
Thank you
#1 - Posted 19 November 2013 - 09:58 AM
- Back to top
I don't think that's possible.
When you pause the script,all timers and hotkeys stop running.
You can pause=>resume it from other script but not with the same.
DetectHiddenWindows,On
^w::
PostMessage,0x111,65404,,,the window title,class or whatever you want to use.
Sleep,5000
PostMessage,0x111,65404,,,the window title,class or whatever you want to use.
Return
#2 - Posted 19 November 2013 - 10:18 AM
- Back to top
That suspends the other script, I want to pause it, what should I change?
#3 - Posted 19 November 2013 - 02:28 PM
- Back to top
Why do you need to pause it and why willSleep not suffice? If it's running a single thread, you could simply do:
^w:: Sleep, 5000
#4 - Posted 19 November 2013 - 02:39 PM
OS: Windows 7 Ultimate / Windows 8.1 Pro | Editor: Notepad++
- Back to top
Because in my script I have the following function so I focus whatever window is under my mouse:
ActivateWinUM:
MouseGetPos,,, WinUMID
WinActivate, ahk_id %WinUMID%
return
And sometimes I need to right click something and I need to stop the script so that function doesnt steal the focus on what I want to do. So I need a few seconds, thats why I want to pause it.
Ex: use that and try to right click on your desktop and you'll see that the function will steal your focus and you cant do nothing except pause the script, do what you want do to, and unpause it again. Thats what I need
Thanks for all your help
#5 - Posted 19 November 2013 - 02:54 PM
- Back to top
✓ Best Answer
Best Answer
That suspends the other script, I want to pause it, what should I change?
It's actually 65403 not 4
You need to add the window name of the script you want to pause.
For example your script is caller Test.ahk
So the window for that script will be called
Path to the script\Test.ahk - AutoHotkey vthe AHK version number.
So
DetectHiddenWindows,On
SetTitleMatchMode,2
^w::
PostMessage,0x111,65403,,,Test.ahk - AutoHotkey
Sleep,5000
PostMessage,0x111,65403,,,Test.ahk - AutoHotkey
Return
Edit:
You can also do something like this with your script
Loop { If GetKeyState("LShift","P") KeyWait,LShift MouseGetPos,,, WinUMID WinActivate, ahk_id %WinUMID% Sleep,100 }
if LShift is pressed down,wait for it to be released and then continue activating windows below the mouse cursor.
That way you can hold shift and then use the right button
#6 - Posted 19 November 2013 - 03:16 PM
- Back to top
You can also do something like this with your script
This is probably the best answer.
#7 - Posted 19 November 2013 - 03:37 PM
OS: Windows 7 Ultimate / Windows 8.1 Pro | Editor: Notepad++
- Back to top
Thank you, now works fine
#8 - Posted 19 November 2013 - 04:11 PM
- Back to top
Also rather that constantly activating the window,you can do this
Loop { If GetKeyState("LShift","P") KeyWait,LShift MouseGetPos,,, WinUMID,,2 IfWinNotActive,ahk_id %WinUMID% WinActivate, ahk_id %WinUMID% Sleep,100 }
#9 - Posted 19 November 2013 - 04:57 PM
- Back to top
Source: https://www.autohotkey.com/board/topic/99108-pause-script-for-x-seconds/