Pause script when a hotkey is pressed

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
sisa
Posts: 5
Joined: 03 Sep 2018, 12:21

Pause script when a hotkey is pressed

03 Sep 2018, 12:37

Hello,
I use the following simple script to spam the e key:

Code: Select all

F2::
If State=50
State=Off
else
State=50
SetTimer SendKey, %State%
Return

SendKey:
Send e
Return
Is it possible to modify that script in a way that it stops spamming the e key when any other hotkey combination is pressed and continue to spam e after a hotkey is released?
I would appreciate any help.
Rohwedder
Posts: 7630
Joined: 04 Jun 2014, 08:33
Location: Germany

Re: Pause script when a hotkey is pressed

03 Sep 2018, 14:49

Hallo,
every other Hotkey must begin with "Thread, NoTimers"!
Try:

Code: Select all

q::
Thread, NoTimers
Sleep, 4000
Return

F2::
If State=50
State=Off
else
State=50
SetTimer SendKey, %State%
Return

SendKey:
Send e
Return
sisa
Posts: 5
Joined: 03 Sep 2018, 12:21

Re: Pause script when a hotkey is pressed

03 Sep 2018, 16:38

Thats exactly what I was looking for. Thanks!
sisa
Posts: 5
Joined: 03 Sep 2018, 12:21

Re: Pause script when a hotkey is pressed

15 Oct 2018, 13:59

Is it also possible to pause the script when Ctrl or Alt are pressed and unpause the script when Ctrl or Alt are released?
I have tried the following but for some reason it doesn't seem to work:

Code: Select all

Ctrl up::pause off

Ctrl::pause on
Rohwedder
Posts: 7630
Joined: 04 Jun 2014, 08:33
Location: Germany

Re: Pause script when a hotkey is pressed

16 Oct 2018, 00:11

Hallo,
try:

Code: Select all

*LCtrl::
	Suspend ;Suspend Hotkeys and Hotstrings
	Pause,,1 ;Pause script including all timer
	KeyWait, Ctrl
	Suspend, Off
	Pause, Off
Return
sisa
Posts: 5
Joined: 03 Sep 2018, 12:21

Re: Pause script when a hotkey is pressed

16 Oct 2018, 05:10

Hi,
thanks again!
Rohwedder wrote:
16 Oct 2018, 00:11
try:

Code: Select all

*LCtrl::
	Suspend ;Suspend Hotkeys and Hotstrings
	Pause,,1 ;Pause script including all timer
	KeyWait, Ctrl
	Suspend, Off
	Pause, Off
Return
Something turns wrong when I integrate this in my script.

My script looks like that:

Code: Select all

F11::
If State=50
State=Off
else
State=50
SetTimer SendKey, 200
Return

SendKey:
Send {Media_Next}
Return

*LCtrl::
	Suspend ;Suspend Hotkeys and Hotstrings
	Pause,,1 ;Pause script including all timer
	KeyWait, Ctrl
	Suspend, Off
	Pause, Off
Return
I would like to do the following:
Spam the "Media_Next" hotkey and when ctrl is pressed it should pause spamming "Media_Next" for as long as I hold down the Ctrl key and then continue to spam "Media_Next" when ctrl key is released.
Key combinations with Ctrl such as Ctrl+1, Ctrl+2, etc should however work while Ctrl is hold down.
Rohwedder
Posts: 7630
Joined: 04 Jun 2014, 08:33
Location: Germany

Re: Pause script when a hotkey is pressed

16 Oct 2018, 05:46

Hallo,
forget Suspend and Pause and try:

Code: Select all

SendKey:
IF !GetKeyState("Ctrl","P")
    Send {Media_Next}
Return
sisa
Posts: 5
Joined: 03 Sep 2018, 12:21

Re: Pause script when a hotkey is pressed

16 Oct 2018, 12:04

That does the job. Thanks once again!

Return to “Ask for Help (v1)”

Who is online

Users browsing this forum: Chunjee and 107 guests