cancel/stop the previous action...

Ask gaming related questions (AHK v1.1 and older)
Wasso
Posts: 5
Joined: 03 Jul 2015, 19:26

cancel/stop the previous action...

03 Jul 2015, 19:37

Hello, i need help for scripting

I was able to script my moves in a game but the problem is i may need the cancel the action and use another combination. instead

So here is what i did

Tab::
MouseClick , LEFT , , , 1, 2
Sleep, 400
MouseClick , LEFT , , , 1, 2
Sleep, 400
MouseClick , LEFT , , , 1, 2
Sleep, 400
MouseClick , LEFT , , , 1, 2
Sleep, 400
MouseClick , LEFT , , , 1, 2, D
Sleep, 1000
MouseClick , LEFT , , , 1, 2, U
Sleep, 400

and

q::
send, 1
Sleep, 50
MouseClick , RIGHT , , , 1, 2, D
Sleep, 500
MouseClick , RIGHT , , , 1, 2, U
Sleep, 400

the scripts are all good one by one.... what i really need is to cancel my 'Tab' action upon pressing 'q' button and do the 'q' action instead...

To be more clear: I want a way to end a script without Quitting the app, even if it's in the middle of executing some code. Is that possible?

any help would greatly appreciated
User avatar
evilC
Posts: 4824
Joined: 27 Feb 2014, 12:30

Re: cancel/stop the previous action...

27 Jul 2015, 05:47

You could maybe do it with Suspend or some method of "Quitting" the app, but you would probably be better off using some simple logic.

Something like this:

Code: Select all

Interrupt := 0

Tab::
MouseClick , LEFT , , , 1, 2
Sleep, 400
if (Interrupt) return
MouseClick , LEFT , , , 1, 2
Sleep, 400
if (Interrupt) return
MouseClick , LEFT , , , 1, 2
Sleep, 400
if (Interrupt) return
MouseClick , LEFT , , , 1, 2
Sleep, 400
if (Interrupt) return
MouseClick , LEFT , , , 1, 2, D
Sleep, 1000
if (Interrupt) return
MouseClick , LEFT , , , 1, 2, U
Sleep, 400
return

q::
Interrupt := 1
send, 1
Sleep, 50
MouseClick , RIGHT , , , 1, 2, D
Sleep, 500
MouseClick , RIGHT , , , 1, 2, U
Sleep, 400
Interrupt := 0
return
Wasso
Posts: 5
Joined: 03 Jul 2015, 19:26

Re: cancel/stop the previous action...

29 Jul 2015, 15:04

Tnx for the reply. But this doesnt work either. Now the issue is when i hit tab button it only does the first action which is 'MouseClick , LEFT , , , 1, 2' and then stops... so i cant tell if the interrupt code works or not
Wasso
Posts: 5
Joined: 03 Jul 2015, 19:26

Re: cancel/stop the previous action...

08 Aug 2015, 13:10

okay i want to try something different. What should i add to script if i want the 'Tab's button on push down only... I mean when i hit the 'Tab button it does what it does but is it possible to do the process on holding pushing down the button (Tab) only and when i release it stops the script running even if its in the middle of the process.
Wasso
Posts: 5
Joined: 03 Jul 2015, 19:26

Re: cancel/stop the previous action...

17 Aug 2015, 19:25

M8 tnx for your answers but that wasnt what i've asked. I want the Tab button do its job only when i push it down and when i release it i want the script stop even if its in the middle of the process

IE:
I hold down the Tab button and it starts
MouseClick , LEFT , , , 1, 2
Sleep, 400
MouseClick , LEFT , , , 1, 2
Sleep, 400
MouseClick , LEFT , , , 1, 2
Sleep, 400

and i released tab (so the rest of the actions whhich is below wont be triggered)

MouseClick , LEFT , , , 1, 2
Sleep, 400
MouseClick , LEFT , , , 1, 2, D
Sleep, 1000
MouseClick , LEFT , , , 1, 2, U
Sleep, 400

is it possible?
User avatar
evilC
Posts: 4824
Joined: 27 Feb 2014, 12:30

Re: cancel/stop the previous action...

18 Aug 2015, 03:12

Yes, as I said, you want to hook into the up event.
Another way to do it would be to use GetKeyState() to check the state of the key, but the way I show here is probably more CPU efficient.

Also notice that I put the click parameters into an array, so we can easily check the state of the button without having to have loads of if blocks in the code.

(Untested code, but hopefully you get the idea...)

Code: Select all

button_held := 0
button_sequence := [{btn: "LEFT", count: 1, speed: 2, event: "", sleep: 400}, {btn: "LEFT", count: 1, speed: 2, event: "D", sleep: 1000}, {btn: "LEFT", count: 1, speed: 2, event: "U", sleep: 400}]

Tab::
	; Ignore key repeats (The down event will fire repeatedly while the key is held)
	if (button_held){
		return
	}
	
	max := button_sequence.length()
	ctr := 1
	
	; Set up an infinite loop
	loop {
		if (!button_held){
			; Button released, stop
			break
		}
		MouseClick, % button_sequence[ctr].btn, , , % button_sequence[ctr].count, % button_sequence[ctr].speed, % button_sequence[ctr].event
		Sleep % button_sequence[ctr].sleep
		ctr++
		; reset ctr when we get to the end of the array
		if (ctr > max){
			ctr := 1
		}
	}
	return

Tab up::
	; Set button_up to 0, so the main loop stops.
	button_held := 0
	return

Return to “Gaming Help (v1)”

Who is online

Users browsing this forum: spisi69 and 23 guests