Double use of shift keys Topic is solved

Get help with using AutoHotkey (v2 or newer) and its commands and hotkeys
pafec
Posts: 6
Joined: 05 Apr 2024, 15:51

Double use of shift keys

Post by pafec » 08 May 2024, 15:42

Sorry if this is easy, but I don't know where I could start consulting the manual.

I would like that Left shift key sends arrow down if no key is pressed after it.
If a key is pressed after Left shift key, it should send the up case letter.

Same with Rigth shift key, but with arrow up.

How should it be done?

Best regards
User avatar
Seven0528
Posts: 393
Joined: 23 Jan 2023, 04:52
Location: South Korea
Contact:

Re: Double use of shift keys

Post by Seven0528 » 08 May 2024, 19:16

 Using InputHook isn't the easiest feature for beginners.
Therefore, I wanted to solve this problem without InputHook, but I couldn't find a neat way.
Above all, it was just too bothersome(?), so I just went ahead and used InputHook to solve this problem. Umm...
I hope someone else can provide code that's easier to understand than mine. Thank you.

Code: Select all

#Requires AutoHotkey v2.0
#SingleInstance Force

~LShift::  {
    static init := false, ih
    if (!init)    {
        init := true
        ih := inputHook("L0")
        ih.BackspaceIsUndo := false
        ih.MinSendLevel := 101
        ih.keyOpt("{All}","VE")
        ih.KeyOpt("{LShift}","-E")
    }
    ih.start()
    keyWait("LShift")
    ih.stop()
    if (ih.EndKey == "")
        send("{Down}")
}

~RShift::  {
    static init := false, ih
    if (!init)    {
        init := true
        ih := inputHook("L0")
        ih.BackspaceIsUndo := false
        ih.MinSendLevel := 101
        ih.keyOpt("{All}","VE")
        ih.KeyOpt("{RShift}","-E")
    }
    ih.start()
    keyWait("RShift")
    ih.stop()
    if (ih.EndKey == "")
        send("{Up}")
}
  • English is not my native language. Please forgive any awkward expressions.
  • 영어는 제 모국어가 아닙니다. 어색한 표현이 있어도 양해해 주세요.
ntepa
Posts: 434
Joined: 19 Oct 2022, 20:52

Re: Double use of shift keys

Post by ntepa » 08 May 2024, 19:44

An easier way?

Code: Select all

#Requires AutoHotkey v2.0
#SingleInstance Force

~LShift::  {
    keyWait("LShift")
    if A_PriorKey = "LShift"
        send("{Down}")
}

~RShift::  {
    keyWait("RShift")
    if A_PriorKey = "RShift"
        send("{Up}")
}
or this:

Code: Select all

#Requires AutoHotkey v2.0
#SingleInstance Force

~LShift Up:: {
    if A_PriorKey = "LShift"
        send("{Down}")
}

~RShift Up:: {
    if A_PriorKey = "RShift"
        send("{Up}")
}
Last edited by ntepa on 08 May 2024, 20:15, edited 1 time in total.
niCode
Posts: 305
Joined: 17 Oct 2022, 22:09

Re: Double use of shift keys  Topic is solved

Post by niCode » 08 May 2024, 19:51

I originally had something like ntepa's but found that pressing too many shifts in a row caused shift+arrow to be used so I had to send shift up.

Code: Select all

~LShift::SendArrow('down')
~RShift::SendArrow('up')

SendArrow(direction) {
    key := SubStr(A_ThisHotkey, 2)
    KeyWait(key)
    Send('{Shift up}')
    if A_PriorKey = key {
        Send('{' direction '}')
    }
}
pafec
Posts: 6
Joined: 05 Apr 2024, 15:51

Re: Double use of shift keys

Post by pafec » 14 May 2024, 04:16

First: thanks!
Second: I would like to understand better your code, it is some steps above my level, any tips welcome. @niCode
Third: Could it be possible to use shift with mouse click? Right now I can't select several cells in excel using Shift + Left click (it acts as arrow).

Best regards
niCode
Posts: 305
Joined: 17 Oct 2022, 22:09

Re: Double use of shift keys

Post by niCode » 14 May 2024, 06:35

One idea:

Code: Select all

#HotIf GetKeyState('Shift', 'P')        ; if shift is physically being pressed down
~*LButton::SendArrow(false)             ; LButton sends a false to SendArrow to interrupt it
#HotIf                                  ; blank #HotIf prevents below hotkeys from being affected by above #HotIf condition


~LShift::SendArrow('down')              ; LShift behaves as normal and calls SendArrow function with down as parameter
~RShift::SendArrow('up')                ; RShift behaves as normal and calls SendArrow function with up as parameter


SendArrow(direction) {
    static key := ''                    ; initialize variable 'key' : static means the value is remembered between calls

    if not direction {                  ; if direction is false
        key := ''                       ; reset key to interrupt comparison after the KeyWait so it fails and doesn't send directional key
        return                          ; exit early
    }

    key := SubStr(A_ThisHotkey, 2)      ; key is the hotkey called, starting at the second value e.g. ~LShift hotkey is just LShift
    KeyWait(key)                        ; wait for key to be physically released
    Send('{Shift up}')                  ; send shift up

    if A_PriorKey = key {               ; if a prior key is the same as the key pressed to get here, i.e. no other key was pressed during the hold
        Send('{' direction '}')         ; send direction sent by shift key
    }
}
Post Reply

Return to “Ask for Help (v2)”