One key to cycle between two others

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

One key to cycle between two others

07 Oct 2018, 20:05

Through research I found lots of questions & answers that dance around what I would like to do

GOAL:
Press "MButton" and draws Machine Gun which is key "3"
Press "MButton" again and switches to Knife which is key "4"
Press "MButton" again and switches back to Machine Gun key "3"

So each time I press "MButton", weapons are cycled between "3" & "4" so my character will have one or the other weapon, depending on how many times I press "MButton"

This page:>>>> https://autohotkey.com/board/topic/5614 ... ne-hotkey/<<<

MButton::
key++
if key = 1
Send, 3
else if key = 2
{
Send, 4
key = 0
}
Return

This seemed to be on the right track and tried multiple variations of what appeared might work, but did nothing in game :(

Any assistance would be greatly appreciated, Eric :)
I have a bit of experience opening and sending commands to game console and CMD.exe... just ask :)
Evil-e
Posts: 262
Joined: 04 Sep 2018, 11:09

Re: One key to cycle between two others

08 Oct 2018, 05:59

Thanks

I actually came across that page yesterday and tried make it work for me, but don't know how to adapt it :( I tried the following two options, but syntax is incorrect

MButton::
If !Toggle_Variable
{
3 <---- gives error message
or
{3} <---- gives error message
}
Else
{
4 <---- gives error message
or
{4} <---- gives error message
}
Toggle_Variable := !Toggle_Variable
Return
I have a bit of experience opening and sending commands to game console and CMD.exe... just ask :)
swagfag
Posts: 6222
Joined: 11 Jan 2017, 17:59

Re: One key to cycle between two others

08 Oct 2018, 06:20

Code: Select all

MButton::
  if (toggle := !toggle)
    send 3
  else
    send 4
return
Evil-e
Posts: 262
Joined: 04 Sep 2018, 11:09

Re: One key to cycle between two others

08 Oct 2018, 16:43

swag..... you always chime in to help, but gosh-darned if I can ever get your scripts to work :( Nearly all scripts I try, beyond the most basic, like.... e::d... give me grief :headwall:

Do you know of any alternate ways to write this?

Thanks, in advance :)
I have a bit of experience opening and sending commands to game console and CMD.exe... just ask :)
User avatar
Xtra
Posts: 2744
Joined: 02 Oct 2015, 12:15

Re: One key to cycle between two others

08 Oct 2018, 17:44

Try easy step 1 (Run as admin)
https://autohotkey.com/boards/viewtopic.php?t=11084

If it still doesnt work use SetKeyDelay (easy step 3) with 50 for press duration.

And of course use code posted by swagfag.

HTH
Evil-e
Posts: 262
Joined: 04 Sep 2018, 11:09

Re: One key to cycle between two others

08 Oct 2018, 19:24

Thanks.... I already have AHK running on this game for something else and is running as admin. This upper section is what I am already using.

The "Action" key is N and "Enter / Exit vehicle" key is M. Sometimes a required "Action" is near a car and character runs to the car, rather than use elevator, so its not perfect... lol
I was hoping this delay would give enough separation between "N" & "M" input, but will experiment with 2000ms and test again
----------------------------------------------------------------------------------------
g::
Send {n down}
KeyWait, 1000
send {m down}
KeyWait, g
Send {n up}{m up}
----------------------------------------------------
This is how I am interpreting Xtra's post with swags code....... as I'm sure you already see, this script is invalid :(
---------------------------------------------------
MButton::
if (toggle := !toggle)
send 3
Sleep 20
else
send
Sleep 20
Return
--------------------------------------------------

OK... please tell me where I have gone wrong :)
I have a bit of experience opening and sending commands to game console and CMD.exe... just ask :)
User avatar
Xtra
Posts: 2744
Joined: 02 Oct 2015, 12:15

Re: One key to cycle between two others

08 Oct 2018, 21:11

Change:KeyWait, 1000
to
Sleep, 1000

Also you need a return for your hotkey g

It would look like this:

Code: Select all

g:: 
Send {n down} 
Sleep, 1000 
send {m down}
KeyWait, g
Send {n up}{m up}
return
Evil-e
Posts: 262
Joined: 04 Sep 2018, 11:09

Re: One key to cycle between two others

09 Oct 2018, 10:02

Thank you, X :)

Your recommendation of Sleep over KeyWait is an improvement, but went from this guy :beard: to this guy :morebeard: waiting that full second for the car door to open..... so I went all Capt. Janeway and played god with time :HeHe:

----------------------------------------------
g::
Send {n down}
Sleep, 500
send {m down}
KeyWait, g
Send {n up}{m up}
Return
------------------------------------------------

I have again tried to add swags code and still does not work :(

-----------------------------------------------
g::
Send {n down}
Sleep, 500
send {m down}
KeyWait, g
Send {n up}{m up}
Return <------------------------ tried with / without this line (wasn't quite understaning this particular part of your post)
MButton::
if (toggle := !toggle)
send 3
else
send 4
return
-----------------------------------------------

It would be nice to get the MButton to toggle weapons, but meh if I don't :rainbow:
I have a bit of experience opening and sending commands to game console and CMD.exe... just ask :)
User avatar
Xtra
Posts: 2744
Joined: 02 Oct 2015, 12:15

Re: One key to cycle between two others

09 Oct 2018, 11:19

The return for the g:: hotkey it to prevent code below it from running, Did you want the weapons to swap also when you press g?

If MButton is used as a keybind in your game then you need to change the hotkey to ~MButton:: to allow both the game and ahk to use MButton.

HTH
Evil-e
Posts: 262
Joined: 04 Sep 2018, 11:09

Re: One key to cycle between two others

09 Oct 2018, 13:22

To answer your question, no... "G" is strictly for "Action" & "Enter / Exit Vehicle" functions. My little brain would explode if I was to try and keep track of 4 functions under the same key. No doubt, I would get flustered and pull a gun
and enter the elevator blasting civilians when all I wanted was to open a car door... lol

You have been a big help and will try the ~MButton:: as an option. I have done lots of research on AHK posts and threads trying to make various actions work, but my brain turns to mush very quickly. Give me ANYTHING that is broken and I can
come up with an idea, design and make a repair part and fix it. Give me a piece of paper with all kinds of equations and..... well, that is why I did not go to college.

I thank you for your help and will get back to some gaming now, as I would rather play them than "fix" them ;)

Peace, Eric :beer:

I got a kick-ass beard tho :morebeard:

PS. If it is OK, I would like to hit you up in a day or two with one or two troublesome scripts that are higher on the list than the one I proposed in this thread
I have a bit of experience opening and sending commands to game console and CMD.exe... just ask :)
Evil-e
Posts: 262
Joined: 04 Sep 2018, 11:09

Re: One key to cycle between two others

09 Oct 2018, 17:46

DUDE!

I am such a dummy :crazy:
-----------------------------------------------------------
g::
Send {m down}
Sleep, 500
send {n down}
KeyWait, g
Send {m up}{n up}
Return
MButton::
Send {3 down}
Sleep, 250 <------------ this is basically the time it takes to repress the key, so exactly what I wanted to do :dance:
send {4 down}
KeyWait, MButton
Send {3 up}{4 up}
return
---------------------------------------------------------
This is my current script to do exactly what I want. Funny how I always need to step back and look at something for a minute to see what is right there in front of me.

Many thanks, XMan... beers on me
:beer:
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: rikoahk and 57 guests