2 keys with one hotkey.

Ask gaming related questions (AHK v1.1 and older)
Drasky
Posts: 4
Joined: 05 Dec 2016, 03:51

2 keys with one hotkey.

05 Dec 2016, 04:07

What I wanted to do was make a hotkey that had two keys with a very small delay. I did that.

$z::
Send {c down}{x down}
sleep 0.5
Send {c up}{x up}
return

In addition I wanted to add 2 more keys so that when I press z they will hold themselves milliseconds before the action above begins and release at the same time it ends.
$z::
Send {RButton up}{Tab up}
sleep 2
Send {RButton down}{Tab down}
Send {c down}{x down}
sleep 0.5
Send {c up}{x up}
return

...but it failed miserably because I have no idea how to go about it.

I appreciate all the help I can get.
User avatar
evilC
Posts: 4823
Joined: 27 Feb 2014, 12:30

Re: 2 keys with one hotkey.

05 Dec 2016, 08:33

I wanted to add 2 more keys so that when I press z they will hold themselves milliseconds before the action above begins and release at the same time it ends
So holding c and x works, but you want to hold RButton and Tab while c and x are pressed?

Code: Select all

$z::
Send {RButton down}{Tab down}{c down}{x down}
sleep 10
Send {c up}{x up}{RButton up}{Tab up}
return
By the way - decimals are not valid for sleep, it must be whole numbers. Also, the minimum amount of time that the AHK sleep command supports is 10 - any lower value (except 0, which has special meaning) will still sleep for ~10ms
Drasky
Posts: 4
Joined: 05 Dec 2016, 03:51

Re: 2 keys with one hotkey.

05 Dec 2016, 09:44

evilC wrote:
I wanted to add 2 more keys so that when I press z they will hold themselves milliseconds before the action above begins and release at the same time it ends
So holding c and x works, but you want to hold RButton and Tab while c and x are pressed?

Code: Select all

$z::
Send {RButton down}{Tab down}{c down}{x down}
sleep 10
Send {c up}{x up}{RButton up}{Tab up}
return
By the way - decimals are not valid for sleep, it must be whole numbers. Also, the minimum amount of time that the AHK sleep command supports is 10 - any lower value (except 0, which has special meaning) will still sleep for ~10ms
Thanks, I just did that and it works most of the time, except sometimes it does not.

Sometimes pressing Z just causes either x or c be performed by itself.
Let me try to explain what I am trying to hotkey.
For me to accomplish what I am aiming RButton and Tab button has to be held down before pressing c and x at the same time for the effect I am trying to get.

How can I get that?
User avatar
evilC
Posts: 4823
Joined: 27 Feb 2014, 12:30

Re: 2 keys with one hotkey.

05 Dec 2016, 11:00

Using my code, RButton and Tab are held before c and x.
Maybe there needs to be a delay between holding RButton / Tab and holding c / x

So try replacing Send {RButton down}{Tab down}{c down}{x down} with:

Code: Select all

Send {RButton down}{Tab down}
Sleep 50
Send {c down}{x down}
Drasky
Posts: 4
Joined: 05 Dec 2016, 03:51

Re: 2 keys with one hotkey.

05 Dec 2016, 23:17

I think the part with RButton and Tab is functioning as it should, but sometimes I still get a c or x instead of the combination I want to achieve.
Drasky
Posts: 4
Joined: 05 Dec 2016, 03:51

Re: 2 keys with one hotkey.

06 Dec 2016, 17:25

Alright, so I am pretty sure the problems stems from:
$z::
Send {RButton down}{Tab down}
Sleep 50
Send {c down}{x down}
Sleep 10
Send {c up}{x up}{RButton up}{Tab up}
return

I need to find a way to make the time window smaller than Sleep 10, which I don't think is possible.
Also it turns out I need a milliseconds delay between pressing c and x.
hugin
Posts: 15
Joined: 17 Aug 2016, 01:33

Re: 2 keys with one hotkey.

06 Dec 2016, 18:36

Drasky wrote:Alright, so I am pretty sure the problems stems from:
$z::
Send {RButton down}{Tab down}
Sleep 50
Send {c down}{x down}
Sleep 10
Send {c up}{x up}{RButton up}{Tab up}
return

I need to find a way to make the time window smaller than Sleep 10, which I don't think is possible.
Also it turns out I need a milliseconds delay between pressing c and x.
C and X, like this?

Code: Select all

Send {c down}
Sleep 10
Send {x down}
Or was it a rhetorical questions to what you want and can't achieve?

Also remember that AutoHotkey is not multi threaded, so it will only read from one end to the other.
I'm far from an expert, but have you considered that your keyboard and your system can't register any faster inputs?
I think I read somewhere that a Sleep set at 10ms will be registered by WIN OS system to be around 16ms.
So in fact you don't get 10ms but around 16ms in fact.

Experts, correct me if I am wrong.

Return to “Gaming Help (v1)”

Who is online

Users browsing this forum: No registered users and 80 guests