Send prefix key if no combinations match Topic is solved

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
runyanavenue
Posts: 4
Joined: 04 Oct 2022, 16:10

Send prefix key if no combinations match

Post by runyanavenue » 04 Oct 2022, 16:22

I have these two parts in my scrypt:
********************************************************************
Numpad0::
...
return

Numpad0 & Numpad1:: (this doesn't matter, i am just showing that i have some combinations for Numpad0)
...
return
********************************************************************

Problem: when i hold the prefix key {Numpad 0} and click a key, that doesn't match any combinations, only the clicked key gets sent to output.
Example: i was typing 127.0.0.1 on the numpad, but i only got 127...1. So I figured it was happening because i was clicking {Numpad 0} and '.' simultaneously, and {Numpad 0} was ignored as it is a prefix key.
I was wondering: if i hold the prefix key and then click some key, that doesn't match any combinations, could both of them be send to output?

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

Re: Send prefix key if no combinations match

Post by mikeyww » 04 Oct 2022, 17:43

Welcome to this AutoHotkey forum!

With your custom combo, your prefix key fires by itself on release. It will work if you release the key before pressing the next key.

runyanavenue
Posts: 4
Joined: 04 Oct 2022, 16:10

Re: Send prefix key if no combinations match

Post by runyanavenue » 04 Oct 2022, 20:30

Yes, but it is really annoying when typing fast. I also use spacebar as another prefix, so the problem is even worse in this case. Was just wondering if there is a way around it.

Rohwedder
Posts: 7645
Joined: 04 Jun 2014, 08:33
Location: Germany

Re: Send prefix key if no combinations match

Post by Rohwedder » 05 Oct 2022, 01:24

Hallo,
try:

Code: Select all

~Numpad0 & Numpad1::
SendInput, {Bs}
SoundBeep
Return
or without sending the BackSpace:

Code: Select all

Numpad0::
Input, Key, L1
SendInput,% [0][InStr(A_ThisHotkey,"Numpad0")] "{" Key "}"
Numpad0 Up::Input
#IF GetKeyState("Numpad0","P")
Numpad1:: ; Numpad0 & Numpad1::
Input
SoundBeep
Return

runyanavenue
Posts: 4
Joined: 04 Oct 2022, 16:10

Re: Send prefix key if no combinations match

Post by runyanavenue » 05 Oct 2022, 08:34

@Rohwedder I tried this, but it didn't work. Numpad0:: and Numpad0 Up:: are completely ignored if you press some other key with a prefix key, which is Numpad0. I guess ahk just works that way - if you have clicked some key while holding the prefix key then ahk looks for combinations and, if it didn't find any, ignores prefix and sends the other pressed key. There is probably some way to do what i want, but it most likely requires some shenanigans.

Rohwedder
Posts: 7645
Joined: 04 Jun 2014, 08:33
Location: Germany

Re: Send prefix key if no combinations match  Topic is solved

Post by Rohwedder » 05 Oct 2022, 11:29

I have now integrated the two hotkey combinations Numpad0 & Numpad1 and Numpad0 & Numpad3. With both comes here the associated MsgBox. When entering other Numpad0 & (Key) combinations 0 and the Key is sent.

Code: Select all

Numpad0::
Numpad0 := True
Input, Key, L1
Numpad0 Up::
Input
SendInput,% [0][Numpad0] "{" Key "}"
Numpad0 := False , Key := ""
Return
#IF GetKeyState("Numpad0","P")
Numpad1:: ; Hotkey: Numpad0 & Numpad1
Input
MsgBox,,, your pressed Numpad0 & Numpad1, 1
Return
Numpad3:: ; Hotkey: Numpad0 & Numpad3
Input
MsgBox,,, your pressed Numpad0 & Numpad3, 1
Return
#IF

runyanavenue
Posts: 4
Joined: 04 Oct 2022, 16:10

Re: Send prefix key if no combinations match

Post by runyanavenue » 08 Oct 2022, 03:16

@Rohwedder
Yes, this is exactly what i was looking for, thank you!
Most people have keys that have no text bound to them as a prefix key probably, so it is not really a problem for most people.

Post Reply

Return to “Ask for Help (v1)”