Re: How to abort running function on new hotkey press?

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
AfcaEric
Posts: 8
Joined: 29 Sep 2018, 06:29

How to abort running function on new hotkey press?

01 Oct 2018, 07:17

Hi All,

I think i have simple question but i can't find the answer yet.

This is the script:

Code: Select all

Numpad4::
Click, 131, 190
Sleep 400
Click, 222, 832
Sleep 200
Click, 1429, 1015
var := WaitPixelColor(0xE1FE7F,806,291,1000)
If ( var = 0 )
	Click, 1671, 741
	Sleep 100
	Click, 1044, 666
return

Numpad5::
Click, 131, 190
Sleep 400
Click, 986, 830
Sleep 200
Click, 1429, 1015
var := WaitPixelColor(0xE1FE7F,806,291,1000)
If ( var = 0 )
	Click, 1671, 741
	Sleep 100
	Click, 1044, 666
return
The script is running fine. It performs 3 clicks and then waits for a certain pixelcolor. The "WaitPixelColor" has a timeout of 1000 miliseconds (var := WaitPixelColor(0xE1FE7F,806,291,1000)
I just want to know if it's possible to abort the current running action when i press a new hotkey.

For example:
1. I press Numpad4
2. The function performs a few clicks and than waits for 1 second if a certain pixelcolor appears at XY
3. I don't want to wait the full 1 second and want to perform Numpad5

Is that possible?
MannyKSoSo
Posts: 440
Joined: 28 Apr 2018, 21:59

Re: How to abort running function on new hotkey press?

01 Oct 2018, 08:50

So depending on how the function you have set up in your script, which I am going to guess its some kind of loop, then you can use a global variable with a toggle. Basically you will have your Numpad4 part going and contained within your function have an if statement looking for the toggle to activate. If the toggle activates it will trigger an early return statement to leave the function early. Note that I said a global variable however you could do a check for a specific button like If GetKeyState and whatever button you want with a return if it passes that statement. Both of these should work just fine for what you need.

Edit: Somehow the post managed to go wonky and decided that I'm the one who created the post ??? Don't know why it did, but just ignore that.

Return to “Ask for Help (v1)”

Who is online

Users browsing this forum: Descolada, Google [Bot] and 321 guests