Help with simple script

Ask gaming related questions (AHK v1.1 and older)
wjrastan
Posts: 4
Joined: 19 Jan 2018, 12:41

Help with simple script

19 Jan 2018, 14:59

I'm trying to get a script working that will use one hotkey to send a key then send different keys with additional presses. If 1 second passes without a hotkey press it will reset to send the first key. It should be able to send up to 3 different keys but be easy to modify for a different amount.

Using an example from these forums I got this to work but it lacks the ability to reset itself to send the first key.

Code: Select all

Count := 1

#If (Count == 1)
1::
{	
	Send 2
	Count++
	return
}	
#If (Count == 2)
1::
{
	Send 3
	Count++
	return
}
#If (Count == 3)
1::
{
	Send 4
	Count := 1
	return
}
If you were to use this code the script would reset Count to 1 if more than 1 second elapsed after any 1 press. I tried some different SetTimer statements but can't get anything that works. Thank you for any help you may be able provide.
User avatar
TrippyHippyDan
Posts: 10
Joined: 16 Jan 2018, 10:48

Re: Help with simple script

19 Jan 2018, 15:16

Hi, I am not sure if you were still looking to hit 1 ever or not because as is this will not (if you want it to just continue the pattern only start at 0 instead of 1)

Code: Select all

Count := 1
1::
if (Count == 1)
	{	
	Send, 2
	Count := Count + 1
		Return
	}	
if (Count == 2)
	{	
	Send, 3
	Count := Count + 1
		Return
	}	
if (Count == 3)
	{	
	Send, 4
	Count :=  1
		Return
	}
	Return
wjrastan
Posts: 4
Joined: 19 Jan 2018, 12:41

Re: Help with simple script

19 Jan 2018, 15:24

TrippyHippyDan wrote:Hi, I am not sure if you were still looking to hit 1 ever or not because as is this will not (if you want it to just continue the pattern only start at 0 instead of 1)
I'm using 1 as a hotkey to send 2, 3 and 4 in sequence. The way it is written it will reset to send the first key after the last key has been sent.

I would like it to reset to send the first key after 1 second or after the last key has been sent.

Edit: It does not need to send 1.
wjrastan
Posts: 4
Joined: 19 Jan 2018, 12:41

Re: Help with simple script

19 Jan 2018, 15:38

To help clarify:

Press hotkey > send first key

If more than 1 second elapses reset to send first key

Press hotkey > send second key

If more than 1 second elapses reset to send first key

Press hotkey > send third key

reset to send first key
User avatar
TrippyHippyDan
Posts: 10
Joined: 16 Jan 2018, 10:48

Re: Help with simple script

19 Jan 2018, 16:01

wjrastan wrote:To help clarify:

Press hotkey > send first key

If more than 1 second elapses reset to send first key

Press hotkey > send second key

If more than 1 second elapses reset to send first key

Press hotkey > send third key

reset to send first key
In that case what I posed should be working for you in AHK :)
User avatar
TrippyHippyDan
Posts: 10
Joined: 16 Jan 2018, 10:48

Re: Help with simple script

19 Jan 2018, 16:11

@wjrastan also alternatively if you are looking for it to actually send 2-4 and not subbing in another command or send this can do it more efficiently

Code: Select all

Count := 1
1::
if (Count < 3)
	{	
	Count := Count + 1
	Send, %Count%
			Return
	}	
if (Count == 3)
	{	
	Send, 4
	Count :=  1
		Return
	}
	Return
Otherwise the post from before will work as you requested.
Spoiler
User avatar
eventhorizon
Posts: 158
Joined: 27 Oct 2016, 14:22

Re: Help with simple script

19 Jan 2018, 16:29

here is one way it might be done..I used the windows notepad to test the program and it appears to work as you stated. See if this helps. This method will allow you to send a custom key sequence with a custom delay between the keys and a custom reset time.
I use a method similar to this in the mmorpgs i play to send fight sequences to the game.

Code: Select all

#SingleInstance, Force
SendMode, Event
settitlematchmode,2 ;<- so you don't need the whole nopad window title
detecthiddenwindows On ;<- so the script can detect the target window even if hidden

keys = 2,3,4 ;<- keys to be sent
stringsplit, keylist, keys, `, ;<- set up keys to send
slp = 50 ;<- normal delay between keys
keyID = 1 ;<- initialize the first key to send
lasttime = %A_Tickcount% ;<- set up the last time a key was sent
maxdelay = 1000 ;<- one second timeout

; uses windows notepad for testing
tstwin = "Untitled"
ifwinnotexist, %tstwin%
{	run, Notepad.exe
}
WinActivate, %tstwin%
return


esc:: ;<- exits the script entirely
	tooltip ;<- turns off the tooltip message
	MsgBox,0x1000,Line%A_LineNumber%,Script Ended. ;<- signals the end of the script
	ExitApp


1:: ;<- uses the 1 key for the hotkey...
	; check for delay timeout
	thistime = %A_Tickcount%
	if ((thistime - lasttime) > maxdelay)
	{	KeyID = 1
	}
	
	; check for end of key list
	if (keyID > keylist0)
	{	keyID = 1
	}
	
	; send the key and sleep
	key := keylist%keyID%
	send %key%
	sleep %slp%
	
	; update the key id and last time
	keyID++
	lasttime = %thistime%

return


A computer lets you make more mistakes faster than any invention in human history – with the possible exceptions of handguns and tequila.
wjrastan
Posts: 4
Joined: 19 Jan 2018, 12:41

Re: Help with simple script

19 Jan 2018, 17:10

Thank you all for your help so far.

@eventhorizon I got this to work as needed in notepad and am tweaking it for my game atm. I will need to modify it for different hotkeys and key sequences. Can I just launch separate scripts for each hotkey/key sequence combo?
User avatar
eventhorizon
Posts: 158
Joined: 27 Oct 2016, 14:22

Re: Help with simple script

19 Jan 2018, 17:47

I don't know quite what you have in mind but what i did with my fight sequences goes something like this...
within my game i have a number of different characters of different professions. They all have somewhat different keysets they use when fighting or harvesting etc. What i did for that was to set up an ini file with the character's name as the key. In each ini section for that character is a keyset like the one in the example i gave you. They may have different keys and even a different number of keys in their fight sequences but at the beginning of my script i select one of the characters through a dialog and load their individual keysets into a comman variable then split it out so i can use them exactly like the sample i showed you.
here is a sample ranger from one of my games

Code: Select all

[rick]
name=rick level 40 ranger
longbowkeys=1,500,0/2,3000,5000/3,500,6000
swordkeys=1,2000,0/2,1000,2000/3,2000,6000/4,4000,0/5,500,12000
autoheal=1
healkey=637,940,0xAC1404,0xAC1404,6,1000,0
notes=none
each key in the key sequence uses the key number, a cast time in ms, a recharge time in ms
for self healing the health bar position is the location of the point being scanned on the screen, the color that's supposed to be there if they don't need a heal, the heal key number, it's cast time and it's recovery time. As you can see it can get a bit complex For fight sequences the key sequences are split the first time on the / to give a complete key definition that's sent to the fight handler. The fight handler takes each key sent to it and splits it again to get the specific key to send, how long to sleep after sending, and how long before the key is ready to be used again. The fight handler loops until the mob or mobs i'm fighting are dead then stops. One button on the mouse starts this whole process and can stop it on command if needed to switch targets. So, yeah it's something you might need to grow into.

One way you could do this simply in your script is to give each keyset you want to use a slightly different name and select them off a list in a dialog box. An example might be

Code: Select all

setnames = rickset,babeset,tinyset
rickset = 1,2,5,4,9
babeset = 2,8,{f1},9,!6
tinyset = 5,4,^3
or something similar, Then you could read the set names...select the one you want... load the selected variable... split it up and proceed to kick butt.
A computer lets you make more mistakes faster than any invention in human history – with the possible exceptions of handguns and tequila.

Return to “Gaming Help (v1)”

Who is online

Users browsing this forum: Google [Bot], hiahkforum, phalanxdarken and 122 guests