Is it possible to map SHIFT?

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
bruin1953
Posts: 9
Joined: 22 Jan 2015, 10:27

Is it possible to map SHIFT?

22 Jan 2015, 10:47

Pressing and releasing LShift or RShift does not do anything.
Is it possible to map them without affecting their normal functions?
Similarly, is it possible to map LShift + LShift (pressing LShift twice)

Appreciate education!
Randy31416
Posts: 58
Joined: 15 Jan 2014, 19:09

Re: Is it possible to map SHIFT?

22 Jan 2015, 22:28

I have used "~LShift Up::RunSomeFunction()" successfully; I don't know if I've tried plain "~LShift::RunSomeFunction()". The ~ says to pass the keystroke along normally. This is in a very large complex script with many layers of hotkeys, so it sometimes has taken trial and error to get a key like this positioned well with respect to other keys which might use shift. As for pressing the key twice. I think you require internal timing logic to detect this for yourself (at least that's what I have to do). In any case, I do use AHK to trap shift keypresses. The ones I really like are "+RShift::RunThis()" and "+LShift::RunThat()", which fire when both shift keys are pressed (one firing when the left is pressed first and the other firing when the right is pressed first).
GEV
Posts: 1002
Joined: 25 Feb 2014, 00:50

Re: Is it possible to map SHIFT?

23 Jan 2015, 03:09

Code: Select all

; LShift + RShift
<+RShift:: MsgBox, LShift + RShift

; RShift + LShift
>+LShift:: MsgBox, RShift + LShift

;	2xLShift

~LShift::
If (A_PriorHotKey = "~LShift Up" AND A_TimeSincePriorHotkey < 300)
	MsgBox, 2xLShift
return

~LShift Up:: Send, ^c{Shift Up} ;	copy

;	2xRShift

~RShift::
If (A_PriorHotKey = "~RShift Up" AND A_TimeSincePriorHotkey < 300)
	MsgBox, 2xRShift
return

~RShift Up:: Send,{Shift Up}
bruin1953
Posts: 9
Joined: 22 Jan 2015, 10:27

Re: Is it possible to map SHIFT?

01 Feb 2015, 18:16

Thanks to both.

2xLShift, 2xRShift, and LShift + RShift are working beautifully.
So are LShift and RShift, but WITHOUT the tilde.
With the tilde, Shift + A etc will also fire the macro. Not desirable.
Thank again for the great help.
guest3456
Posts: 3463
Joined: 09 Oct 2013, 10:31

Re: Is it possible to map SHIFT?

02 Feb 2015, 01:02

bruin1953 wrote:Pressing and releasing LShift or RShift does not do anything.
Is it possible to map them without affecting their normal functions?
yes, I've done this. I mapped LShift and RShift to send left and right parenthesis respectively (as suggested here), while still maintaining their shifting behavior to capitalize characters.

The solution was from this link:
http://www.autohotkey.com/board/topic/1 ... ntrol-key/

Code: Select all

$~*LShift::
   ;msgbox, %A_ThisHotkey% is down
   ;// when you hold down the key, this hotkey fires constnatly due to the normal OS-level repeat
   ;// so we only want to store the time from the initial downpress, not each OS-repeat)
   ;// and then during the 'up' hotkey, we reset this timestamp back to 0
   if (!LShift_down_timestamp)      
      LShift_down_timestamp := A_TickCount
   
   ;// if any other modifiers are down along with this key, then we will not send the replacement key (left parens)
   if (!LShift_modifiers_are_pressed)
      LShift_modifiers_are_pressed := (GetKeyState("Control", "P") ||  GetKeyState("Alt", "P") || GetKeyState("LWin", "P") || GetKeyState("RWin", "P"))
return

$~LShift up::
   ;msgbox, %A_PriorKey%
   ;msgbox, %A_ThisHotkey%
   ;// check if EITHER shift key was the last key pressed
   ;// this allows accidental 'rolling': presing Lshift then Rshift very fast, where you hadn't fully released the LShift before RShift went down
   ;// also, you must press and release LShift within 300ms, otherwise this doesn't trigger. 
   ;// i found myself sometimes holding LShift for a while, planning on capitalizing a letter
   ;// but then releasing the key, causing this hotkey to trigger erroneously
   if (A_PriorKey ~= "LShift|RShift") && (!LShift_modifiers_are_pressed) && (A_TickCount - LShift_down_timestamp < 300)
      Send, {Shift Down}9{Shift Up}         ;// send left parenthesis
   LShift_modifiers_are_pressed := false
   LShift_down_timestamp := 0
return

This can also be used for CTRL or ALT, since they similarly do nothing upon a single downpress and release, but instead are only used in combination with other keys

bobsundquist

Re: Is it possible to map SHIFT?

06 Nov 2015, 14:01

Here is a script that uses left shift to turn off caps lock (regardless of current state) and right shift to turn on caps lock (regardless of current state) while retaining their normal functions if held while pressing another key.

; Capitalist
;
; LShift CapsLock Off
; RShift CapsLock On
; {CapsLock}&{letter} {CAPITAL_LETTER}

#SingleInstance force
#Persistent

Menu, Tray, Add ;divider line
Menu, Tray, Add, CapsLock, ToggleCapsLock
Menu, Tray, Default, CapsLock
IconFile0 := "small_a.ico"
IconFile1 := "BIG_A.ico"
State0 := "Off"
State1 := "On"
Goto, UpdateIcon

RShift & LButton::SendInput +{Click}
~RShift::
{
SetCapsLockState, on
Goto, UpdateIcon
}

LShift & LButton::SendInput +{Click}
~LShift::
{
SetCapsLockState, off
Goto, UpdateIcon
}

CapsLock::
{
NextState := 1 - GetKeyState("Capslock", "T")
SetCapsLockState, on
Gosub, UpdateIcon
Input, Keys, V L1, {CapsLock}
If ErrorLevel = Max
{
NextState := 1 - NextState
}
Return
}

CapsLock Up::
{
SendInput {CapsLock}
if !NextState
{
SetCapsLockState, off
}
Goto, UpdateIcon
}

ToggleCapsLock:
Sleep,40 ;because double click can temporarily turn off CapsLock
if GetKeyState("Capslock", "T")
{
SetCapsLockState, Off
}
else
{
SetCapsLockState, On
}
Goto, UpdateIcon

UpdateIcon:
IconNumber := GetKeyState("Capslock", "T")
IconFile = IconFile%IconNumber%
IconFile := %IconFile%
Menu, Tray, Icon, %IconFile%, 1
State = State%IconNumber%
State := %State%
Menu, Tray, Tip,CapsLock %State%
if IconNumber
{
Menu, Tray, Check, CapsLock
}
else
{
Menu, Tray, Uncheck, CapsLock
}
Return
JJohnston2
Posts: 204
Joined: 24 Jun 2015, 23:38

Re: Is it possible to map SHIFT?

07 Nov 2015, 18:35

@bobsundquist, Please use code boxes when posting scripts or script excerpts... they format the code nicely, link keywords automatically to the help pages and keep the script from taking up too much vertical space in the post.

Return to “Ask for Help (v1)”

Who is online

Users browsing this forum: Descolada and 182 guests