Javascript required
Skip to content Skip to sidebar Skip to footer

Autohotkey Pause a Script for 5 Seconds Then Continue

  • Members
  • 8 posts
  • Last active: Jul 07 2016 04:52 AM
  • Joined: 05 Nov 2011

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 :)


  • Back to top

vsub

  • Members
  • 1098 posts
  • Last active: Sep 28 2015 09:48 AM
  • Joined: 10 Nov 2011

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

  • Back to top

TyCuS

  • Members
  • 8 posts
  • Last active: Jul 07 2016 04:52 AM
  • Joined: 05 Nov 2011

That suspends the other script, I want to pause it, what should I change?


  • Back to top

Masonjar13

  • Members
  • 1517 posts
  • Last active:
  • Joined: 16 Sep 2012

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

OS: Windows 7 Ultimate / Windows 8.1 Pro | Editor: Notepad++

  • Back to top

TyCuS

  • Members
  • 8 posts
  • Last active: Jul 07 2016 04:52 AM
  • Joined: 05 Nov 2011

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 :p

Thanks for all your help :)


  • Back to top

vsub

  • Members
  • 1098 posts
  • Last active: Sep 28 2015 09:48 AM
  • Joined: 10 Nov 2011

✓  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


  • Back to top

Masonjar13

  • Members
  • 1517 posts
  • Last active:
  • Joined: 16 Sep 2012

You can also do something like this with your script

This is probably the best answer.


OS: Windows 7 Ultimate / Windows 8.1 Pro | Editor: Notepad++

  • Back to top

TyCuS

  • Members
  • 8 posts
  • Last active: Jul 07 2016 04:52 AM
  • Joined: 05 Nov 2011

Thank you, now works fine :)


  • Back to top

vsub

  • Members
  • 1098 posts
  • Last active: Sep 28 2015 09:48 AM
  • Joined: 10 Nov 2011

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 }            

  • Back to top

coppinruchey.blogspot.com

Source: https://www.autohotkey.com/board/topic/99108-pause-script-for-x-seconds/