trigger a different key on second press

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
didimaox
Posts: 22
Joined: 02 Feb 2022, 07:21

trigger a different key on second press

Post by didimaox » 29 Sep 2022, 07:17

Hello everyone

I am currently using the following script :

Code: Select all

c & '::
Send, {m}
I'd like to make it so that if i press c and ' simultaneously a second time, the key ' goes off.

Thanks in advance

User avatar
mikeyww
Posts: 26945
Joined: 09 Sep 2014, 18:38

Re: trigger a different key on second press

Post by mikeyww » 29 Sep 2022, 07:31

Hi,

What does "goes off" mean?

didimaox
Posts: 22
Joined: 02 Feb 2022, 07:21

Re: trigger a different key on second press

Post by didimaox » 29 Sep 2022, 07:38

Hello

I just meant that the script should input the ' key, if that makes sense

User avatar
mikeyww
Posts: 26945
Joined: 09 Sep 2014, 18:38

Re: trigger a different key on second press

Post by mikeyww » 29 Sep 2022, 08:09

Code: Select all

c::c
c & '::
Send % A_TickCount < end ? "'" : "m"
end := A_TickCount + 600
Return

didimaox
Posts: 22
Joined: 02 Feb 2022, 07:21

Re: trigger a different key on second press

Post by didimaox » 29 Sep 2022, 09:51

Hello and thank you for your help

It's closer to what i want, but the problem is that if i press c+', then hold the c key and don't press the ' key after a certain amount of time, the script starts over and inputs m instead of '

And if i increase the value of the tickount, even if i release both keys i have to wait some time for the script to "reinitialize" ( meaning that, lets say, i have a tickcount value of 10 000. If i press c+', release both buttons, then try do it again, ahk inputs the ' key instead of m that is supposed to go first.

Sorry if i'm being unclear

User avatar
mikeyww
Posts: 26945
Joined: 09 Sep 2014, 18:38

Re: trigger a different key on second press

Post by mikeyww » 29 Sep 2022, 10:08

You are clear about the problem, but not what should happen in your script. You have to decide the criteria, precisely, for which key to send, and exactly when (under what circumstance). You can post that explanation in your reply below.

didimaox
Posts: 22
Joined: 02 Feb 2022, 07:21

Re: trigger a different key on second press

Post by didimaox » 29 Sep 2022, 12:03

Ok!
So, when the c Key is held, pressing ' for the first Time should trigger the m Key. Every subsequent presses of the ' Key ( while c is held) should trigger '.
When the c Key is released, the script should be reset, meaning that if i press c+', m should be triggered next
Is it clearer?

User avatar
mikeyww
Posts: 26945
Joined: 09 Sep 2014, 18:38

Re: trigger a different key on second press

Post by mikeyww » 29 Sep 2022, 12:24

Yes.

Code: Select all

c::c
c & '::Send % A_PriorKey = "c" ? "m" : "'"

didimaox
Posts: 22
Joined: 02 Feb 2022, 07:21

Re: trigger a different key on second press

Post by didimaox » 29 Sep 2022, 12:36

yes this is exactly what i was looking for and it works great! thank you

Post Reply

Return to “Ask for Help (v1)”