Home row modifiers

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
Shwansmeister
Posts: 8
Joined: 20 Feb 2022, 08:05

Home row modifiers

Post by Shwansmeister » 20 Feb 2022, 08:36

Hi!
I am trying to write a script that uses the home row keys jKL; and FDSA as SHIFT, CTRL, ALT and WIN respectively when held down. similar on how people do it on these 40% QMK keyboards.
I wrote the following script to make J act as shift while held down but type a normal j when it is just tapped (i.e. normal typing)

Code: Select all

j::
    Send {Text}j
    KeyWait, j, t0.1
        if errorlevel = 1
            Send, {Backspace}
            Send, {Shift Down}
            KeyWait, j
            Send, {Shift Up}   
Return
the problem is that when I hold down the J key it starts to repeatedly send J (capitalized as if I'm pressing SHIFT+ j) which seems strange because I specifically told it to just send the text j. I also don't understand why it would repeat like that as it should just wait for me until I release the j key and not return to the beginning correct?
Also the send j anyway and then send backspace seems pretty janky to me :p but when i tried to put the send j after the keywait (in a if errorlevel = 0) it would type a j upon releasing the key and that messes with my typing.
I am pretty new to ahk so besides answers for my question, any tips on how you would write something like this better are greatly appreciated. thx!
Attachments
image.png
image.png (7.66 KiB) Viewed 2315 times

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

Re: Home row modifiers

Post by mikeyww » 20 Feb 2022, 10:31

Ideas are below.

Code: Select all

$j::
$+j::
If Instr(A_PriorKey, "Shift") {
 Send J
 Return
} Else KeyWait, j, T.2
If ErrorLevel { ; Held
 Send {Shift down}
 KeyWait, j
 Send {Shift up}
} Else Send j
Return
Explained: Dollar prefix

Shwansmeister
Posts: 8
Joined: 20 Feb 2022, 08:05

Re: Home row modifiers

Post by Shwansmeister » 21 Feb 2022, 11:53

Thanks a lot!
this is exactly what I was looking for.

Shwansmeister
Posts: 8
Joined: 20 Feb 2022, 08:05

Re: Home row modifiers

Post by Shwansmeister » 04 Mar 2022, 05:46

Follow up question:

I notice that when I'm typing fast I often encounter "rollover" when I press the next key but the j key is still pressed down. because the j key only fires on release this results in the next pressed key being sent before the j key.
is there a way to immediately set the ErrorLevel to 0 when any other key is pressed so that it sends j and then the next pressed key.

thanks in advance!

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

Re: Home row modifiers

Post by boiler » 04 Mar 2022, 07:38

This is why I never found modifications to the home row of keys to be useful. In theory, they make a lot of sense for a touch typist not having to move your hands away from home row. But as a touch typist, you probably are also likely typing pretty fast, and even the small delays that scripts cause in keys being recognized disrupts the flow of your normal typing. I'm not saying you won't find a solution that works for you. I'm just saying that's what I found while trying to accomplish the same thing.

Shwansmeister
Posts: 8
Joined: 20 Feb 2022, 08:05

Re: Home row modifiers

Post by Shwansmeister » 04 Mar 2022, 07:52

yeah, the fire on release and having to wait 200ms before the shift activates were really weird at first, but I've actually gotten used to that pretty fast.
If I could only figure out the rollover issue I think I'd have a pretty solid setup :)

Elequosoraptor
Posts: 18
Joined: 11 Oct 2017, 09:04

Re: Home row modifiers

Post by Elequosoraptor » 24 Nov 2022, 20:17

You might not be working on this anymore, but I was experimenting with the same general idea. One idea I've been playing with, but haven't fully tested, is having each key send its character on a press as usual, but upon holding the key down for long enough it automatically backspaces and then holds down the appropriate modifier.

Below is the code I used to turn f and j into long-press shift modifiers. This may or may not work for you, and I am still unsure about the effects of sending a backspace in a non text window (since that is unavoidable with these hotkeys). I also have heard that keywait is not good to use for this, and its better to define a separate key up hotkey, but I'm not really sure if it matters for this use case.

Disclaimers aside, this totally fixes the rollover issue since typing is unaffected, keys are sent on a press, not a release, as is normal. The altered behavior only matters if you hold the key down, and the automatic backspacing means that in text fields you have a visual indicator (the backspace) for when the modifier is in play.

I specify RShift and LShift so that the behavior of f when holding down j and vice versa is unaffected.

Code: Select all

$<+f::Return
$f::{
    SendInput("f")
    if(!KeyWait("f","T0.130")){
        SendInput("{BackSpace}")
        SendInput("{LShift down}")
        KeyWait("f")
        SendInput("{LShift up}")
    }
}

$>+j::Return
$j::{
    SendInput("j")
    if(!KeyWait("j","T0.130")){
        SendInput("{BackSpace}")
        SendInput("{RShift down}")
        KeyWait("j")
        SendInput("{RShift up}")
    }
}

eugenesv
Posts: 178
Joined: 21 Dec 2015, 10:11

Re: Home row modifiers

Post by eugenesv » 04 Nov 2023, 14:30

Elequosoraptor wrote:
24 Nov 2022, 20:17
You might not be working on this anymore, but I was experimenting with the same general idea. One idea I've been playing with, but haven't fully tested, is having each key send its character on a press as usual, but upon holding the key down for long enough it automatically backspaces and then holds down the appropriate modifier.
One partially fixable downside of this approach is when you use it in a non-text area, the cleaning backspace may trigger a command instead of doing nothing (like going back in history in your browser). So you might want to use Accessibility/UIA library to only trigger the behavior in editable elements (though this detection isn't 100%)

Another is that sometimes it'd clean up the 2nd/3rd letter instead of the original f

FYI I've recently toyed with a potentially better approach where you actually track the sequence of keys and decide whether to enable the HOLD-mod functionality viewtopic.php?f=83&t=122851

Post Reply

Return to “Ask for Help (v1)”