Page 1 of 1
Double use of shift keys
Posted: 08 May 2024, 15:42
by pafec
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
Re: Double use of shift keys
Posted: 08 May 2024, 19:16
by Seven0528
 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}")
}
Re: Double use of shift keys
Posted: 08 May 2024, 19:44
by ntepa
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}")
}
Re: Double use of shift keys Topic is solved
Posted: 08 May 2024, 19:51
by niCode
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 '}')
}
}
Re: Double use of shift keys
Posted: 14 May 2024, 04:16
by pafec
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
Re: Double use of shift keys
Posted: 14 May 2024, 06:35
by niCode
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
}
}