i key to toggle 4 others Topic is solved

Ask gaming related questions (AHK v1.1 and older)
Evil-e
Posts: 262
Joined: 04 Sep 2018, 11:09

i key to toggle 4 others

05 Nov 2018, 14:42

I know, I know.... this has been asked a hundred times and all the threads I find, don't quite work for me :( I am playing
Marvel Ultimate Alliance and has the option of swapping between all four characters directly, but would like to use
T to just cycle through all four keys mapped to J ~ K ~ L ~ H

I have the following script, courtesy of Xtra, that will toggle between two keys:
-------------------------------------------------------------------------------------------------------------------
$t::SendToggler("j","k")<---------------------- would like to add 2 more keys, but my attempts have failed

SendToggler(key1,key2,dur:=100)
{
static key
key := key=key1 ? key2 : key1
Send, {%key% Down}
Sleep dur
Send, {%key% Up}
}
return
--------------------------------------------------------------------------------------------------------------------
Works fantastic for two keys.... but need 4. I have tried to modify this script to add a couple more keys, but
have been unsuccessful.


Tinkering around with ideas, this will cycle through all 4 characters, but....... well, take a look :crazy:
-------------------------------------------------------------------------------------------------------------------------
t::
Send {j down}
Sleep, 1000
Send {j up}
sleep, 50
Send {k down}
Sleep, 1000
Send {k up}
Sleep, 50
Send {l down}
Sleep, 1000
send {l up}
Sleep, 50
Send {h down}
Sleep, 1000
Send {h up}
KeyWait, t
Send {j up}{k up}{l up}{h up}
return
---------------------------------------------------------------------------------------------------------------------------
The modestly trained AHK eye will see the same thing I did when I made it, but wanted to see the result "in game" anyway.

Sho nuff.... just like I figured, it goes through all 4 characters then stops where I started :(

Any help would be appreciated :morebeard:
I have a bit of experience opening and sending commands to game console and CMD.exe... just ask :)
awel20
Posts: 211
Joined: 19 Mar 2018, 14:09

Re: i key to toggle 4 others

05 Nov 2018, 15:29

Code: Select all

objKeys := ["j", "k", "l", "h"]
nKey := 1
return

$t::
    KeySender( objKeys[nKey] )
    nKey := 1 + (nKey = objKeys.MaxIndex() ? 0 : nKey)
return

KeySender(key, dur:=100)
{
    Send, {%key% Down}
    Sleep, dur
    Send, {%key% Up}
    return
}
Evil-e
Posts: 262
Joined: 04 Sep 2018, 11:09

Re: i key to toggle 4 others

05 Nov 2018, 16:29

Thank you, but unable to make it work for me :(

At first, I thought maybe a type-0, as the last return is above the bracket, but moving it did not help. Very similar to script
I posted at the top, but several attempts to "merge" the two did not work either.

The way you wrote it appears that I should insert the objKeys within the KeySender line, but my attempts to do so failed.

Can you shed a little light on it for me? :thumbup:
I have a bit of experience opening and sending commands to game console and CMD.exe... just ask :)
awel20
Posts: 211
Joined: 19 Mar 2018, 14:09

Re: i key to toggle 4 others

05 Nov 2018, 16:44

Put these two lines at the top of your script. Before the first hotkey or return. https://autohotkey.com/docs/Scripts.htm#auto

Code: Select all

objKeys := ["j", "k", "l", "h"]
nKey := 1
The return is in the right place for the hotkey and the KeySender function.
Evil-e
Posts: 262
Joined: 04 Sep 2018, 11:09

Re: i key to toggle 4 others

06 Nov 2018, 13:50

Hmmmm... I have done a copy / paste of your entire first script and the objKeys & nKey lines are, as I understand it from this last post, in
the right place:
----------------------------------------------------------------------------------------
objKeys := ["j", "k", "l", "h"]
nKey := 1
return

$t::
KeySender( objKeys[nKey] )
nKey := 1 + (nKey = objKeys.MaxIndex() ? 0 : nKey)
return

KeySender(key, dur:=100)
{
Send, {%key% Down}
Sleep, dur
Send, {%key% Up}
return
}
--------------------------------------------------------------------------------------------

Is this how it should look?

Funny, literally just over a month ago, my use of AHK was limited to the following:

e::w
d::s
s::a
f::d
XButton1::y

..... that's it, REALLY! I am now opening the console sending 20 lines of text intermixed with keys up / down, underscores
the like and now looking to toggle 4 keys with only one. Unthinkable early last month :) [gets off couch and pets cat (again)]

:morebeard:
I have a bit of experience opening and sending commands to game console and CMD.exe... just ask :)
CyL0N
Posts: 211
Joined: 27 Sep 2018, 09:58

Re: i key to toggle 4 others

11 Nov 2018, 15:00

Code: Select all

;needlessly verbose for clarity...

$t::	;sends h,j,k,l in alernating manners so as to allow using a single key to switch between all available characters...
If !thisKey{
	thisKey = h
}Else If (thisKey = "h"){
	thisKey = j
}Else If (thisKey = "j"){
	thisKey = k
}Else If (thisKey = "k"){
	thisKey = l
}Else If (thisKey = "l"){
	thisKey = h
}
;MsgBox % thisKey
Send {%thisKey% down}
Return

OR

Code: Select all

$^t::
lastKey := ListGetNextItem("jklh",,lastKey)
Send {%lastKey% down}
return

ListGetNextItem(ByRef list,delim:="",lastItem:=""){
	If !lastItem
		Return StrSplit(list,delim)[1]	;return first item if last item wasn't specified
	For k,v in StrSplit(list,delim)
		retVal := ( lastItem = v && StrSplit(list,delim)[k+1] ? StrSplit(list,delim)[k+1] : (lastItem = v && !StrSplit(list,delim)[k+1] ? StrSplit(list,delim)[1] : retVal) )
	Return retVal
}
live ? long & prosper : regards
Evil-e
Posts: 262
Joined: 04 Sep 2018, 11:09

Re: i key to toggle 4 others

11 Nov 2018, 22:59

cyLON... man you take all this time to write scripts for me, but gosh darned if I just can't get them to work :(

I tried them both and was sure to use CTRL+t on the second one.... no go. I am really thinking that this is a
compatibility issue with my Windows XP 32 bit. Something about code or what not, seems likely the issue.

I have already accepted that many games I would like to play are not compatible with my machine. It appears
I need to add some AHK functions to that list as well. No worries though, two years back I had 3 identical computers
build with my ultra-custom, one-of-a-kind, super-bad azz Hackmeister XP OS. Insanely stable and and vastly more
user friendly than out-of-the-box Windows XP (Bill Gates would NOT approve).

ZERO spyware, adware, firewalls, anti-virus, no Windows Updates since Aug. 2010 and no Windows File Protection.... my computer is
Bambi in Jurassic Park! I have had 2 occasions in the last 10 years in which a virus forced me to reformat. But, with Norton Ghost Images,
I can reformat with a perfect operating system in literally 5 minutes and not lose 1 single byte of data 8-)

[gotta get off this darned couch (again)(again]

Your help has been above and beyond.... thank you!
:morebeard:
I have a bit of experience opening and sending commands to game console and CMD.exe... just ask :)
User avatar
Xtra
Posts: 2750
Joined: 02 Oct 2015, 12:15

Re: i key to toggle 4 others

12 Nov 2018, 01:01

Code: Select all

$t::Seqkeys("j","k","l","h")

Seqkeys(params*){   ; keys rotation, 8 second reset. 
    static s:=0, c:=0, t:=8000, dur:=100
    max := params.MaxIndex()
    (A_TickCount-s<=t && (c+=1)<=max) ? c : c:=1, s:=A_TickCount
    key := params[c]
    Send, {%key% Down}
    Sleep dur
    Send, {%key% Up}
}
CyL0N
Posts: 211
Joined: 27 Sep 2018, 09:58

Re: i key to toggle 4 others  Topic is solved

12 Nov 2018, 02:29

kay so,if neither mine nor Xtra's solution works for you, it can't be anything but a compatibility issue of some sort... Unfortunately.

i tested it with Arma 3 unit switching(next/previous unit) and it works just fine.
live ? long & prosper : regards
swagfag
Posts: 6222
Joined: 11 Jan 2017, 17:59

Re: i key to toggle 4 others

12 Nov 2018, 03:16

Code: Select all

Keys := ["h", "k", "j", "l"]
q::
Send % "{" key := Keys.RemoveAt(1) " Down"
Sleep 1000
Send {%key% Up}
Keys.Push(key)
Return
Evil-e
Posts: 262
Joined: 04 Sep 2018, 11:09

Re: i key to toggle 4 others

12 Nov 2018, 08:45

I just tried both of the above scripts and, well...... this is a compatibility issue.

Xtra, swag, CyLON & awel.... you help is appreciated :thumbup:

:morebeard:
I have a bit of experience opening and sending commands to game console and CMD.exe... just ask :)

Return to “Gaming Help (v1)”

Who is online

Users browsing this forum: doanmvu and 48 guests