How do I merge these two functions?

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
GuyFawkesGaming
Posts: 6
Joined: 14 Mar 2019, 12:46

How do I merge these two functions?

14 Mar 2019, 13:04

I'm attempting to make it so if I press shift with WASD, the script will send the arrow keys instead. I also want CapsLock to do the same but toggle instead. This is where the script breaks and only the shift or CapsLock section will work. Seams the two sets of instructions need to be merged but I dont know how. Also, is there a way to make it so if you are already holding one of WASD and press Shift it will go to arrow keys instead of continuing WASD input?

Here's the code:

Code: Select all

+w::Up
+s::Down
+a::Left
+d::Right

$w::
If GetKeyState("Capslock","T")
Send {Up}
else
Send w
Return

$s::
If GetKeyState("Capslock","T")
Send {Down}
else
Send s
Return

$a::
If GetKeyState("Capslock","T")
Send {Left}
else
Send a
Return

$d::
If GetKeyState("Capslock","T")
Send {Right}
else
Send d
Return
User avatar
Scr1pter
Posts: 1272
Joined: 06 Aug 2017, 08:21
Location: Germany

Re: How do I merge these two functions?

14 Mar 2019, 16:07

The only Idea I currently have is that you replace all the one liners by three liners.

Instead of
+w::Up

make this:

Code: Select all

+w::
Send {Up}
return
Since you say both scripts work 100% (if they are not combined), I have no other idea.
(I Cannot test it right now anyway)

Cheers!
Please use [code][/code] when posting code!
Keyboard: Logitech G PRO - Mouse: Logitech G502 LS - OS: Windows 10 Pro 64 Bit - AHK version: 1.1.33.09
GuyFawkesGaming
Posts: 6
Joined: 14 Mar 2019, 12:46

Re: How do I merge these two functions?

14 Mar 2019, 16:43

I've done a little more testing with the game I was using this on, turns out I was wrong. Only the Shift hold lines work. The Caps lock and ones you just suggested me don't and cause a weird laggy or no response. Strange cause both worked together on notepad.
User avatar
Scr1pter
Posts: 1272
Joined: 06 Aug 2017, 08:21
Location: Germany

Re: How do I merge these two functions?

14 Mar 2019, 16:56

Ok if it's for a game, SendInput might be more reliable.
Maybe I'll have time tomorrow to test it.
Perhaps some other use can support you.

Cheers!
Please use [code][/code] when posting code!
Keyboard: Logitech G PRO - Mouse: Logitech G502 LS - OS: Windows 10 Pro 64 Bit - AHK version: 1.1.33.09
User avatar
Xtra
Posts: 2750
Joined: 02 Oct 2015, 12:15

Re: How do I merge these two functions?

14 Mar 2019, 17:23

Code: Select all

#If GetKeyState("CapsLock","T")
$w::Up
$a::Left
$s::Down
$d::Right
#IF

*w::Send % GetKeyState("Shift","P") ? "{Up}" : "w"
*a::Send % GetKeyState("Shift","P") ? "{Left}" : "a"
*s::Send % GetKeyState("Shift","P") ? "{Down}" : "s"
*d::Send % GetKeyState("Shift","P") ? "{Right}" : "d"
HTH
GuyFawkesGaming
Posts: 6
Joined: 14 Mar 2019, 12:46

Re: How do I merge these two functions?

15 Mar 2019, 11:59

Xtra wrote:
14 Mar 2019, 17:23

Code: Select all

#If GetKeyState("CapsLock","T")
$w::Up
$a::Left
$s::Down
$d::Right
#IF

*w::Send % GetKeyState("Shift","P") ? "{Up}" : "w"
*a::Send % GetKeyState("Shift","P") ? "{Left}" : "a"
*s::Send % GetKeyState("Shift","P") ? "{Down}" : "s"
*d::Send % GetKeyState("Shift","P") ? "{Right}" : "d"
HTH
This has the opposite effect; Caps works now but shift doesn't. Combining it with the shift functions from the original script or duplicating the Caps ones from this one makes both work, thanks! Now if only there was a way to make WASD go to arrow keys while already being held down (an WASD + shift = arrowkeys in addition to shift + WASD = arrowkeys if you will).
EDIT: I think I figured out why pressing shift while already holding one of WASD doesn't send an arrowkey input; seams the game needs an additional command to let it know the key is no longer being held. Pressing the W key in game then the Up arrow, it ignored the up arrow. The same is also true in the opposite order, Press Up arrow then W and it ignores the W.
GuyFawkesGaming
Posts: 6
Joined: 14 Mar 2019, 12:46

Re: How do I merge these two functions?

16 Mar 2019, 17:48

Well my main request has been solved but does anyone have any advice on how to make WASD keys release with the press of shift and arrow keys release with the release of shift (also capslock)? Probably be best to avoid send commands as the game I'm working on seams allergic to them.
EDIT Again: I've managed to fix the arrow key release with the press of WASD but not the other way around. I've also managed to break the capslock toggle I originally asked for by doing so :oops:
Here's what I got, the last stanza is what make the arrow keys release:

Code: Select all

+w::Up
+s::Down
+a::Left
+d::Right

#If GetKeyState("CapsLock","T")
$w::Up
$a::Left
$s::Down
$d::Right
#IF

~w::sendinput {up up}
~a::sendinput {left up}
~s::sendinput {down up}
~d::sendinput {right up}

Return to “Ask for Help (v1)”

Who is online

Users browsing this forum: Chunjee, mebelantikjaya, rc76 and 310 guests