Two letters key combo

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
HighArn
Posts: 17
Joined: 20 Oct 2021, 08:25

Two letters key combo

Post by HighArn » 07 Jun 2023, 13:04

Hi, stuck with this. I just need that when I press K and L at one time the backspace would be pressed. K and L must act normally when pressed separately. I found a few solution that doesn't work well.

Code: Select all

~k & l::
Send {Backspace}
return
This for example sends k with backspace, adding second backspace is not solution for me.
Others scripts that i found for example send backspace only on key release, k and l separately send on release to, this is bad to.

When i used my mechanical programmable keyboard there is a combo keys with qmk, they are based on timings, like one key after pressing wait for another to make combo, and those are worked pretty well for me.

I tried something like this:

Code: Select all

~k::
lDown:=A_TickCount
keywait l
lDuration:=(A_TickCount-lDown)
If (lDuration<112) {
Send {Backspace}


}
Else
Send k
return

~l & k::
kDown:=A_TickCount
keywait k
kDuration:=(A_TickCount-kDown)
If (kDuration<112) {
Send {Backspace}

}
Else
Send l
return
But this more like a draft, because i'm not really familiar with ahk.
May someone help?

[Mod edit: Moved topic to AHK v1 help, based on posted code and posting history. Please use the right subforums going forward!]

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

Re: Two letters key combo

Post by mikeyww » 07 Jun 2023, 18:42

With custom combinations, the keys are sent upon the release.

Code: Select all

#Requires AutoHotkey v1.1.33
k::k
l::l
k & l::Send `b

HighArn
Posts: 17
Joined: 20 Oct 2021, 08:25

Re: Two letters key combo

Post by HighArn » 08 Jun 2023, 08:47

mikeyww wrote:
07 Jun 2023, 18:42
With custom combinations, the keys are sent upon the release.

Code: Select all

#Requires AutoHotkey v1.1.33
k::k
l::l
k & l::Send `b
Thanks, this works better than others that I found. But problem that k send only after release, and something with timings, sometimes l is typed with backspace together. It is possible to do this way:

1) When k is pressed it waits about 100ms for l and produce backspace, else produce k.
2) When l is pressed it waits about 100ms for k and produce backspace, else produce l.

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

Re: Two letters key combo

Post by mikeyww » 08 Jun 2023, 08:55

You can play around with some things like this.

Code: Select all

#Requires AutoHotkey v1.1.33

~k::
KeyWait l, DT.1
If !ErrorLevel
 Send `b`b`b
Return

Code: Select all

#Requires AutoHotkey v1.1.33
#If GetKeyState("k", "P")
l::Send `b`b
#If
InputHook provides an alternative approach.

HighArn
Posts: 17
Joined: 20 Oct 2021, 08:25

Re: Two letters key combo

Post by HighArn » 08 Jun 2023, 10:41

Code: Select all

#Requires AutoHotkey v1.1.33

~k::
KeyWait l, DT.1
If !ErrorLevel
 Send `b`b`b
Return
This help me to find that solution

Code: Select all

$k::
KeyWait l, DT.1
If !ErrorLevel
 Send {Backspace}
else 
send {k}
Return

$l::
KeyWait k, DT.1
If ErrorLevel
send {l}
Return
Works almost perfect for me, with sending only one backspace. Just little play with timings. Thanks!

Post Reply

Return to “Ask for Help (v1)”