Problem with a hotkey code

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
GGGarikkk
Posts: 6
Joined: 15 Oct 2022, 02:59

Problem with a hotkey code

Post by GGGarikkk » 15 Oct 2022, 08:10

Hello,

I have posted not so long ago a problem with my code. Original post link: viewtopic.php?f=76&t=109473&p=486820#p486820
The problem:

Code: Select all

F1::Suspend
1 & j::left 
1 & k::down 
1 & l::right 
1 & i::up
Basically, what I need to do is to use keys (i, k, j, l) as cursor keys when pressed 1 key first
For example: 1 + j will result in left key.
But the problem with the code is that when I just wanna use 1 key for its native purpose (to type 1) it is disabled.
So, I need:
When pressed "1" key and released type "1"
When pressed "1" key and without releasing other key from the list is pressed (i, k, j, l), then use it as a cursor purpose key
I have received a proper answer, but in the process of utilizing the script new issue came up.

New working code with an issue:

Code: Select all

1 & j::left 
1 & k::down 
1 & l::right 
1 & i::up
1::Send {1}
New issue:
Let's just say I wanna type a number 10. Normally when you do that there is no problem, because the process looks like as follows:
1. Press 1 key
2. Release 1 key
3. Press 0 key
4. Release 0 key

But when you press those keys quickly the process may look like this:
1. Press 1 key
2. Press 0 key
3. Release 1 key
4. Release 0 key

And because of that usually instead of number 10 I type just a 0 (It is not a local problem just with number 10, anything typed in pair with "1" key is usually ends up without "1": typed 1* => get *)
It is understandable from the code why this happens.
To solve this problem I may hardcode all possible combinations of keys with key "1". But what happens when I press 3 keys simultaneously. Hardcode all combinations of two keys pressed with key "1"?
I am sure that there is a simple solution and I would be grateful to see it.

User avatar
boiler
Posts: 17387
Joined: 21 Dec 2014, 02:44

Re: Problem with a hotkey code

Post by boiler » 15 Oct 2022, 08:29

The answer to that issue is also in what I quoted from the documentation in your other thread — the “fire on release” issue discussion and use of the tilde to address it.

GGGarikkk
Posts: 6
Joined: 15 Oct 2022, 02:59

Re: Problem with a hotkey code

Post by GGGarikkk » 15 Oct 2022, 12:08

boiler wrote:
15 Oct 2022, 08:29
The answer to that issue is also in what I quoted from the documentation in your other thread — the “fire on release” issue discussion and use of the tilde to address it.
I tried tilde prefix:

Code: Select all

1 & j::left
1 & k::down 
1 & l::right 
1 & i::up
~1::Send {1}
But now when I press "1" + j key instead of cursor just moving one symbol left it also types two ones: ab_c => Pressed "1" + j => ab1_1c, where _ is cursor position
Am I understanding something wrong?

User avatar
boiler
Posts: 17387
Joined: 21 Dec 2014, 02:44

Re: Problem with a hotkey code

Post by boiler » 15 Oct 2022, 13:57

Try putting the tilde before all the other lines.

Trigun
Posts: 41
Joined: 29 Mar 2017, 01:33

Re: Problem with a hotkey code

Post by Trigun » 15 Oct 2022, 14:41

actually i think he should delete the 1:: reassign too, there is no point in remap a key for do what it already do :-D (and add the tilde ofc on the others)
~1 & j::left
~1 & k::down
~1 & l::right
~1 & i::up

GGGarikkk
Posts: 6
Joined: 15 Oct 2022, 02:59

Re: Problem with a hotkey code

Post by GGGarikkk » 16 Oct 2022, 01:13

Trigun wrote:
15 Oct 2022, 14:41
actually i think he should delete the 1:: reassign too, there is no point in remap a key for do what it already do :-D (and add the tilde ofc on the others)
~1 & j::left
~1 & k::down
~1 & l::right
~1 & i::up
Nope, that is not what I meant. Again, what I need code to do is the following:

1. When pressed "1" + j/k/l/i use it ONLY as cursor keys, without typing "1", just move the cursor
2. When pressed just "1" type "1"
3. When pressed "1" + any other key => type "1" + the other key

There is no problem with first two items in the list.
BUT there is a problem with the third. BECAUSE when you press keys in the following way:
1. Press "1" key
2. Press any other key
3. Release "1" key
4. Release the other key
"1" key is not being detected. So, for example, when I type number "10" (using "1" key and "0" key) the above way, actually what is being typed is just "0", because "1" key is deactivated after pressing other key.

Of course I could write down in code

Code: Select all

1 & j::left
1 & k::down 
1 & l::right 
1 & i::up
1 & 0::Send {1}{0}
1::Send {1}
But then, I will need to write all the combinations "1" key + other key

Is there an easier way to resolve the problem?

User avatar
boiler
Posts: 17387
Joined: 21 Dec 2014, 02:44

Re: Problem with a hotkey code

Post by boiler » 16 Oct 2022, 01:47

I see. Your issue is that by using a normal key as a modifier key, then it doesn’t behave normally like when you generally are typing fast and one key isn’t fully released before the next key, which usually results in both keys being typed (such that most people don’t even realize it’s happening when the type). That’s because the computer types the character as the keys are pressed down in normal operation, but you can’t allow that because you need it to wait and see if another key will be pressed before it’s released. Per the old expression, you are trying to have your cake and eat it too.

That’s the drawback of using a regular key as a modifier key. AHK has to wait to see if you’re going to press another key, so it can’t let its normal function occur unless it were to always let it. You’re expecting it to predict the future: Immediately send 1 upon the down press (normal typing operation) unless I follow it with one of my defined combinations, in which case, don’t send it immediately.

An analogy would be that you want to take off in a plane heading east, and you don’t want to decide the destination until you’re in air. Once in the air, you’ll press a button within the first ten minutes indicating one of four eastbound destinations. But if the ten minutes expires without pressing a button, you want it to go to a westbound destination. And here’s your issue: If you end up not pressing a button, you want it to have been heading west the whole time.

Or if not expecting it to predict the future, you are expecting it to act differently in this case and act upon release instead of how it normally would on the down press, unless you type one of the defined combo keys. But then every other key would have to also be sent on the release to keep them in order in your 10 example. Otherwise it would type 01 (0 on the down press but 1 on the release). You shouldn’t expect AHK to totally change how typing works because you decided to use a regular key as a modifier.

The “solution” is to not use regular keys as modifiers and also expect them to act fully normal in every other context.

GGGarikkk
Posts: 6
Joined: 15 Oct 2022, 02:59

Re: Problem with a hotkey code

Post by GGGarikkk » 16 Oct 2022, 02:00

boiler wrote:
16 Oct 2022, 01:47
I see. Your issue is that by using a normal key as a modifier key, then it doesn’t behave normally like when you generally are typing fast and one key isn’t fully released before the next key, which usually results in both keys being typed (such that most people don’t even realize it’s happening when the type). That’s because the computer types the character as the keys are pressed down in normal operation, but you can’t allow that because you need it to wait and see if another key will be pressed before it’s released. Per the old expression, you are trying to have your cake and eat it too.

That’s the drawback of using a regular key as a modifier key. AHK has to wait to see if you’re going to press another key, so it can’t let its normal function occur unless it were to always let it. You’re expecting it to predict the future: Immediately send 1 upon the down press (normal typing operation) unless I follow it with one of my defined combinations, in which case, don’t send it immediately.

An analogy would be that you want to take off in a plane heading east, and you don’t want to decide the destination until you’re in air. Once in the air, you’ll press a button within the first ten minutes indicating one of four eastbound destinations. But if the ten minutes expires without pressing a button, you want it to go to a westbound destination. And here’s your issue: If you end up not pressing a button, you want it to have been heading west the whole time.

Or if not expecting it to predict the future, you are expecting it to act differently in this case and act upon release instead of how it normally would on the down press, unless you type one of the defined combo keys. But then every other key would have to also be sent on the release to keep them in order in your 10 example. Otherwise it would type 01 (0 on the down press but 1 on the release). You shouldn’t expect AHK to totally change how typing works because you decided to use a regular key as a modifier.

The “solution” is to not use regular keys as modifiers and also expect them to act fully normal in every other context.
I get it, that I am asking for something strange.
The thing is if there was such thing as a wildcard for any key (let's say *), then the problem would be solvable, because instead of having code like this:

Code: Select all

1 & j::left
1 & k::down 
1 & l::right 
1 & i::up
1 & 0::Send {1}{0}
1 & 1::Send {1}{1}
1 & 2::Send {1}{2}
1 & 3::Send {1}{3}
1 & 4::Send {1}{4}
...
1 & z::Send {1}{z}
1::Send {1}
I could just write:

Code: Select all

1 & k::down 
1 & l::right 
1 & i::up
1 & *::Send {1}{*}
1::Send {1}
And then if I press "1" + k/l/i/j it works as it did
And when I press "1" + any other key, it types "1" + the pressed key normally

But anyway, thank you for your time, I figured that I could write down the combinations or just change the modifier key

Post Reply

Return to “Ask for Help (v1)”