key combination Topic is solved

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
User avatar
entropy
Posts: 93
Joined: 17 Oct 2014, 01:45

key combination

Post by entropy » 13 May 2022, 03:58

Hello.

Working in Word:
I’ve created a key combination Tab & q::Send !^+p and I assigned a shortcut which works ok. However, when I press only tab nothing happens. The tab has lost its function.
The meaning of a key combination is to hold down the first key a press the other.
But pressing only once should not trigger the combination.

Is there a way around this?

Thanks!

Helgef
Posts: 4709
Joined: 17 Jul 2016, 01:02
Contact:

Re: key combination  Topic is solved

Post by Helgef » 13 May 2022, 04:12

See :arrow: Custom combinations.

Code: Select all

Numpad0 & Numpad2::Run Notepad
The prefix key loses its native function: In the above example, Numpad0 becomes a prefix key; but this also causes Numpad0 to lose its original/native function when it is pressed by itself. To avoid this, a script may configure Numpad0 to perform a new action such as one of the following:

Code: Select all

Numpad0::WinMaximize A   ; Maximize the active/foreground window.
Numpad0::Send {Numpad0}  ; Make the release of Numpad0 produce a Numpad0 keystroke. See comment below.
Try

Code: Select all

Tab & q::Send !^+p 
Tab::Send {Tab}
Cheers.

User avatar
entropy
Posts: 93
Joined: 17 Oct 2014, 01:45

Re: key combination

Post by entropy » 13 May 2022, 04:33

@Helgef

Code: Select all

Numpad0 & Numpad2::Run Notepad
The prefix key loses its native function: In the above example, Numpad0 becomes a prefix key; but this also causes Numpad0 to lose its original/native function when it is pressed by itself. To avoid this, a script may configure Numpad0 to perform a new action such as one of the following:
Well, this is what I thought too but with this key combination CapsLock & f2::Send ^{f2}!y2e the shortcut is working fine and the caps lock key is still working when I press it once to use it as I normally do.
The same is the case with Shift & tab::Send ""{Left} The shortcut is working as does the shift. This means that I can still use shift to write caps
Try

Code: Select all

Tab & q::Send !^+p 
Tab::Send {Tab}
Cheers.
Your solution did work and thanks! But still, I can't understand why this is not the case with the other key combinations I've mentioned!

Helgef
Posts: 4709
Joined: 17 Jul 2016, 01:02
Contact:

Re: key combination

Post by Helgef » 13 May 2022, 09:44

I suppose caps lock and Shift should be suppressed too. Perhaps @lexikos can clarify this. For shift & tab the documentation recommends using +tab instead.

Cheers.

lexikos
Posts: 9560
Joined: 30 Sep 2013, 04:07
Contact:

Re: key combination

Post by lexikos » 14 May 2022, 03:51

Chris was prone to adding exceptions to rules, trying to guess what the user wants. The standard modifiers and CapsLock are exceptions to the rule. It was surprising to me as well (years ago...).

I guess the documentation doesn't explain why custom combinations work the way they do, only the effects of using them, by example.

Consider how the standard modifiers work: you press Ctrl down, nothing happens, then you press C, and you've activated a shortcut. Keys that aren't normally modifiers have some effect, like entering "0" into the field with the focus. Sometimes that effect can be easily reversed (like a hotstring sending backspaces), but sometimes the effect can be destructive or unpredictable (even in the case of Tab). The only general way for a custom modifier to work is to prevent the key from doing anything when pressed down. So Numpad0 & Numpad1:: suppresses the native function of Numpad0, by blocking the key-down and key-up events.

Standard modifiers "obviously" don't need to be suppressed, because they're already intended to be used as modifiers (except that in some cases, such as games, they might have some other direct effect). When someone uses Shift & Tab, I suppose (and I think Chris supposed) they're far more likely to want Shift to retain its normal functionality than for it to function only with the script's custom combination hotkeys. (I would have preferred to keep it simple, have Shift & Tab block Shift and direct users toward +Tab if they don't want that. ~Shift & Tab is another option, but inferior.)

CapsLock, NumLock and ScrollLock do have an effect, but it can almost always be reversed by sending the key again, which is what happens with CapsLock & F2::. Actually, CapsLock is inverted while you are holding it down, and then toggles back when you release it if you have used a custom combination. There are comments in the source code explaining this (basically, it's for people who type quickly... but still use CapsLock :eh: ... and don't release CapsLock before pressing the next key), but why it wasn't designed to block CapsLock by default (when ~ is absent) is anyone's guess.

Side note: you can control suppression (and the current state) of CapsLock with SetCapsLockState AlwaysOff/AlwaysOn.

Helgef
Posts: 4709
Joined: 17 Jul 2016, 01:02
Contact:

Re: key combination

Post by Helgef » 14 May 2022, 03:55

Thanks for the clarification :thumbup: .

Cheers.

User avatar
entropy
Posts: 93
Joined: 17 Oct 2014, 01:45

Re: key combination

Post by entropy » 15 May 2022, 01:19

@lexikos
but why it wasn't designed to block CapsLock by default (when ~ is absent) is anyone's guess.
Thank you for your detailed explanation, however, I’ve used all keys as modifiers and only Tab is losing its original function.
When a key is combined with another, I don’t see a reason that the key must lose its original function.
But this is said from the perspective of a user and not a developer...
Thanks again for clarifying it!

lexikos
Posts: 9560
Joined: 30 Sep 2013, 04:07
Contact:

Re: key combination

Post by lexikos » 15 May 2022, 03:07

@entropy
I worked it out from the perspective of someone who uses a keyboard. :roll:

You have not "used all keys as modifiers" and found only Tab to lose its native function. Only the standard modifier keys, CapsLock, NumLock and ScrollLock keep their native function, as I explained above.

If you use Delete as a modifier, do you want to, by happenstance, delete whatever file or text you have selected, while you are trying to activate a custom combination?

If you use Tab as a modifier and it is not suppressed, the focus will likely switch to the next control, or whitespace will be inserted into an editor, or something else, before you press the other key in the combination. You can confirm this by inserting ~, like ~Tab & q::, which prevents Tab from being suppressed (unless you use Tab:: as well).

User avatar
entropy
Posts: 93
Joined: 17 Oct 2014, 01:45

Re: key combination

Post by entropy » 15 May 2022, 03:35

@lexikos
You're right. I shouldn’t have said that I’ve used all keys and only Tab is losing its native function because I didn’t. I’ve only used those you’ve mentioned.
Sorry and thanks for taking the time to explain it.

forAHK
Posts: 6
Joined: 16 May 2022, 22:43

Re: key combination

Post by forAHK » 16 May 2022, 23:44

@lexikos
Hello lexikos, could you answer my posts [ viewtopic.php?f=76&t=104164 ] at your convenience? I have similar questions.

Post Reply

Return to “Ask for Help (v1)”