Sticky Shift

Post your working scripts, libraries and tools for AHK v1.1 and older
guest3456
Posts: 3463
Joined: 09 Oct 2013, 10:31

Sticky Shift

15 Feb 2017, 22:57

Sticky Shift allows you to press Shift, and then release, and then the next letter will be shifted. This is substantially easier on your hands and fingers. Pressing Shift+Letter at the same time (as a chord) is the normal method, and its way less ergonomic, and timing is also an issue, because you have to press and release both keys at the correct time, otherwise you may get typos, especially at higher speeds.

I didn't like the built-in Windows feature for Sticky Keys, it kept pissing me off: I just wanted to use it for Shift, not the other modifiers such as Ctrl or Alt. I found another script and have modified it, and added the option that a double Shift = CAPSLOCK

Code: Select all


; Sticky Shift
;
; ==================================
; OPTIONS
; ==================================

timeout := 1
                                     ; How long the Shift should stay active 
                                     ; this value is in seconds. use 0.5 for half second
                                     ; if you want a capital A, then press and release Shift, then press 'a' within two seconds
                                     ; after the timeout has elapsed, the shift is no longer in effect

; ----------------------------------

show_indicator := true
                                     ; Whether or not to show a grahpic while the Shift is in progress
                                     ; this value is either 'true' or 'false' with no quotes

; ----------------------------------

double_shift_for_caps := false
                                     ; Should tapping shift twice turn on Capslock?
                                     ; this value is either 'true' or 'false' with no quotes
                                     ; default is 'false', which means a double tap of Shift will cancel the shift

; ----------------------------------

skip_spacebar := false
                                     ; Allow the sequence "Shift,Space,Key" to still shift the Key
                                     ; this value is either 'true' or 'false' with no quotes
                                     ; this means that the Spacebar will not cancel the shift
                                     ; a user wanted to press Shift+Space to be able to shift the next char after Space

; ==================================
; END OF OPTIONS
; ==================================


#NoEnv
#SingleInstance, force
#KeyHistory, 0
ListLines, Off
SetBatchLines, -1
SendMode, Input
Hotkey, LShift,    Shift_Down, on
Hotkey, RShift,    Shift_Down, on
Hotkey, LShift Up, Shift_Up  , on
Hotkey, RShift Up, Shift_Up  , on
; we don't want Control as end key, because we need to be able to press Shift,Ctrl+Left
; we don't want Alt as end key, because Shift+Alt+F should still open up File menu bars
; we don't want Win as end key, because it Shift+Win+D should still send Shift+D
; don't want CapsLock as end key, because Shift down, Caps down/up, Shift still down + M, should invert CapsLock
end_keys := "{F1}{F2}{F3}{F4}{F5}{F6}{F7}{F8}{F9}{F10}{F11}{F12}{Left}{Right}{Up}{Down}"
          . "{Home}{End}{PgUp}{PgDn}{Del}{Ins}{BS}{PrintScreen}{Pause}{AppsKey}{LShift}{RShift}"
; test := 0
if (show_indicator)
{
   HBITMAP := Create_shift_key_png()
   GUIH := Bitmap_GetHeight(HBITMAP)
   GUIW := Bitmap_GetWidth(HBITMAP)
   GUIY := A_ScreenHeight-150
   Gui, -DPIScale -Caption +AlwaysOnTop +ToolWindow
   Gui, Margin, 0, 0
   Gui, Add, Text, x0 y0 w%GUIW% h%GUIH% hwndHPic1
   Bitmap_SetImage(HPic1, HBITMAP)
   Gui, Show, Hide y%GUIY%, StickyShift indicator image
}
return


;F11::ListHotkeys
;Esc::ExitApp


Shift_Down:
   ; tooltip, % "[" A_ThisHotkey "]" ++test ;"`nA_PriorKey=" A_PriorKey    ; if you hold down shift, you'll see this loops after each timeout, so Shift is a repeat key just like any letter, it keeps getting spammed
   if (caps_on)
   {
      SetCapsLockState, Off
      caps_on := false
      return
   }

   trigger_shift_key := A_ThisHotkey        ; needs to be set because A_ThisHotkey gets overwritten by the Up hotkey
   , waiting_for_input := 1

   if (show_indicator)
      Gui, Show, NA

   Send, {%trigger_shift_key% down}
   Input, key, V M L1 T%timeout%, %end_keys%
   ; inputErrorLevel := ErrorLevel

   if (ErrorLevel == "EndKey:LShift") || (ErrorLevel == "EndKey:RShift")
   {
      KeyWait, % SubStr(ErrorLevel, 8)   ; careful, keywait sets its own errorlevel from this point forward
      if (double_shift_for_caps)
      {
         ; tooltip, a second shift press occurred.`ntrigger_shift_key: %trigger_shift_key%`ninputErrorLevel: %inputErrorLevel%
         ; sleep, 1000
         SetCapsLockState, On
         caps_on := true
      }
   }

   ; allow Shift,Space,Space,Space(etc),Letter to work:
   if (skip_spacebar)
      while (key = " ")
         Input key, V M L1 T%timeout%, %end_keys%

    ; tooltip, key=[%key%]`nA_ThisHotkey=[%A_ThisHotkey%]`ntrigger_shift_key=[%trigger_shift_key%]`ninputErrorlevel=%inputErrorLevel%`nhotkeys back on

   if (show_indicator)
      Gui, Hide

   if !(GetKeyState(A_ThisHotkey))
      Send, {%trigger_shift_key% Up}
   waiting_for_input := 0          ; the order of this line could possibly matter, this seems like the best order
   Hotkey, LShift, on
   Hotkey, RShift, on
   Hotkey, LShift Up, on
   Hotkey, RShift Up, on
return



Shift_Up:
   ; tooltip, [%A_ThisHotkey%]`nshift_key=%trigger_shift_key%

   ; if we pressed and released Shift, then the down hotkey is waiting for the next char input
   ; so we want to turn off these hotkeys, so that we can detect another LShift as the Input EndKey
   if (waiting_for_input)
   {
      ; tooltip, turning off hotkeys
      Hotkey, RShift,    off
      Hotkey, RShift Up, off
      Hotkey, LShift,    off
      Hotkey, LShift Up, off
   }

   ; else, the down hotkey is no longer waiting for input.
   ; this only fires if the Up hotkey was triggered AFTER the Input was complete
   ; which means shift was held down during the Input, resulting in a normal Shift+letter simultanous chord.
   ; this is needed because without it, then shift would get 'stuck' down.
   ; test: hold down Shift, and the down hotkey above fires. while still holding shift, we press a letter.
   ; the Input cmd captures the letter and then finally its supposed to Send Shift Up
   ; but we're still physically holding down Shift, so i don't think the virtual Send Shift Up ever goes through
   ; or if it does go through, it somehow blocks our real Shift up release
   else
   {
      Send, {%A_ThisHotkey%}
   }
return







; ##################################################################################
; # This was generated by Image2Include.ahk, you must not change it! #
; #
; # https://autohotkey.com/board/topic/93292-image2include-include-images-in-your-scripts/
; #
; ##################################################################################
Create_shift_key_png(NewHandle := False) {
Static hBitmap := 0
If (NewHandle)
   hBitmap := 0
If (hBitmap)
   Return hBitmap
VarSetCapacity(B64, 8944 << !!A_IsUnicode)
B64 := "iVBORw0KGgoAAAANSUhEUgAAALQAAABKCAYAAAASVX5bAAAAA3NCSVQICAjb4U/gAAAAAXNSR0IArs4c6QAAAARnQU1BAACxjwv8YQUAAAAJcEhZcwAAEnQAABJ0Ad5m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8WNeqe2G3feoTn9KM16XQmtCRGo0sUOB6QLYzNcHsELp5DdeOme5kM92+AhdjJq5ZExcjD7P/B+m3IjZ0VVdJAAAAAElFTkSuQmCC"
If !DllCall("Crypt32.dll\CryptStringToBinary", "Ptr", &B64, "UInt", 0, "UInt", 0x01, "Ptr", 0, "UIntP", DecLen, "Ptr", 0, "Ptr", 0)
   Return False
VarSetCapacity(Dec, DecLen, 0)
If !DllCall("Crypt32.dll\CryptStringToBinary", "Ptr", &B64, "UInt", 0, "UInt", 0x01, "Ptr", &Dec, "UIntP", DecLen, "Ptr", 0, "Ptr", 0)
   Return False
; Bitmap creation adopted from "How to convert Image data (JPEG/PNG/GIF) to hBITMAP?" by SKAN
; -> http://www.autohotkey.com/board/topic/21213-how-to-convert-image-data-jpegpnggif-to-hbitmap/?p=139257
hData := DllCall("Kernel32.dll\GlobalAlloc", "UInt", 2, "UPtr", DecLen, "UPtr")
pData := DllCall("Kernel32.dll\GlobalLock", "Ptr", hData, "UPtr")
DllCall("Kernel32.dll\RtlMoveMemory", "Ptr", pData, "Ptr", &Dec, "UPtr", DecLen)
DllCall("Kernel32.dll\GlobalUnlock", "Ptr", hData)
DllCall("Ole32.dll\CreateStreamOnHGlobal", "Ptr", hData, "Int", True, "PtrP", pStream)
hGdip := DllCall("Kernel32.dll\LoadLibrary", "Str", "Gdiplus.dll", "UPtr")
VarSetCapacity(SI, 16, 0), NumPut(1, SI, 0, "UChar")
DllCall("Gdiplus.dll\GdiplusStartup", "PtrP", pToken, "Ptr", &SI, "Ptr", 0)
DllCall("Gdiplus.dll\GdipCreateBitmapFromStream",  "Ptr", pStream, "PtrP", pBitmap)
DllCall("Gdiplus.dll\GdipCreateHBITMAPFromBitmap", "Ptr", pBitmap, "PtrP", hBitmap, "UInt", 0)
DllCall("Gdiplus.dll\GdipDisposeImage", "Ptr", pBitmap)
DllCall("Gdiplus.dll\GdiplusShutdown", "Ptr", pToken)
DllCall("Kernel32.dll\FreeLibrary", "Ptr", hGdip)
DllCall(NumGet(NumGet(pStream + 0, 0, "UPtr") + (A_PtrSize * 2), 0, "UPtr"), "Ptr", pStream)
Return hBitmap
}
; ----------------------------------------------------------------------------------------------------------------------
; Returns the width of a bitmap.
; ----------------------------------------------------------------------------------------------------------------------
Bitmap_GetWidth(hBitmap) {
   Static Size := (4 * 5) + A_PtrSize + (A_PtrSize - 4)
   VarSetCapacity(BITMAP, Size, 0)
   DllCall("Gdi32.dll\GetObject", "Ptr", hBitmap, "Int", Size, "Ptr", &BITMAP, "Int")
   Return NumGet(BITMAP, 4, "Int")
}
; ----------------------------------------------------------------------------------------------------------------------
; Returns the height of a bitmap.
; ----------------------------------------------------------------------------------------------------------------------
Bitmap_GetHeight(hBitmap) {
   Static Size := (4 * 5) + A_PtrSize + (A_PtrSize - 4)
   VarSetCapacity(BITMAP, Size, 0)
   DllCall("Gdi32.dll\GetObject", "Ptr", hBitmap, "Int", Size, "Ptr", &BITMAP, "Int")
   Return NumGet(BITMAP, 8, "Int")
}
; ----------------------------------------------------------------------------------------------------------------------
; Associates a new bitmap with a static control.
; Parameters:     hCtrl    -  Handle to the GUI control (Pic or Text).
;                 hBitmap  -  Handle to the bitmap to associate with the GUI control.
; Return value:   Handle to the image previously associated with the GUI control, if any; otherwise, NULL.
; ----------------------------------------------------------------------------------------------------------------------
Bitmap_SetImage(hCtrl, hBitmap) {
   ; STM_SETIMAGE = 0x172, IMAGE_BITMAP = 0x00, SS_BITMAP = 0x0E
   WinSet, Style, +0x0E, ahk_id %hCtrl%
   SendMessage, 0x172, 0x00, %hBitmap%, , ahk_id %hCtrl%
   Return ErrorLevel
}
Last edited by guest3456 on 15 Nov 2017, 23:39, edited 4 times in total.

Helgef
Posts: 4709
Joined: 17 Jul 2016, 01:02
Contact:

Re: Sticky Shift

16 Feb 2017, 18:19

Very good! I did not manage to break it :lol:
Good commenting of the code, makes it really easy to follow.
I like the skip_spacebar option, perfect if you get over eager after terminating a sentece with a period, and then starts the next one with a shift before the space.
This post was made this Sticky Script :)

Edit: Additionally, I like that it is idle until you actually use it.
guest3456
Posts: 3463
Joined: 09 Oct 2013, 10:31

Re: Sticky Shift

16 Feb 2017, 20:18

Lol thanks. Yours will likely be way more advanced

Helgef
Posts: 4709
Joined: 17 Jul 2016, 01:02
Contact:

Re: Sticky Shift

17 Feb 2017, 03:36

I don't think I'll continue with it, I think it's redundant, yours can easily modified to do sticky anykey, and as I mentioned, it is idle until you activate the sticky, I prefer that. The only thing that could warrant using other methods is if you want context sensitive specific keys. Eg, if you have both ctrl and shift as sticky key, then I wouldn't want ctlr to work with w in my browser, there would be to high risk that you hit ctrl instead of shift when typing, then you get ctrl+w, which closes the tab, at least in my browser. I would only want physically holding ctrl+w to work, not sticky ctrl+w.
guest3456
Posts: 3463
Joined: 09 Oct 2013, 10:31

Re: Sticky Shift

18 Feb 2017, 17:42

I've updated the script in the OP.

I've added the option to display an on-screen indicator showing while the Shift is active

Helgef wrote:I don't think I'll continue with it, I think it's redundant
Well others may be interested in another technique. You could always just post your work-in-progress in this thread

Helgef
Posts: 4709
Joined: 17 Jul 2016, 01:02
Contact:

Re: Sticky Shift

18 Feb 2017, 18:13

guest3456 wrote: You could always just post your work-in-progress in this thread
Perhaps, but then I'd probably start poking at it again :|

Edit: Nice pop-up! :thumbup:
User avatar
jeeswg
Posts: 6902
Joined: 19 Dec 2016, 01:58
Location: UK

Re: Sticky Shift

19 Feb 2017, 11:47

I use this sometimes so I can drink a cup of tea/coffee while typing.

Code: Select all

$Shift:: ;anywhere - capitalise without holding shift
Input, vText, L1 T1 I
if (ErrorLevel = "Timeout")
	Return
SendInput +{%vText%}
Return
I also use win+space sometimes to capitalise the last word:
(To change capitalisation for the last word.)

Code: Select all

+CapsLock:: ;anywhere - alternative hotkey - capslock
SetStoreCapslockMode, Off
SendInput {CapsLock}
SetStoreCapslockMode, On
Return

;==================================================

#Space:: ;anywhere (text functions) - case - capitalise last word
SendInput ^+{Left}
vText := JEE_GetSelectedText()

StringLower, vLower, vText
StringUpper, vUpper, vText
StringLower, vTitle, vText, T

;(random) --> [lower --> title --> upper -->]
;[same order as MS Word 2003:]
;if lower then title
;if title then upper
;if upper/random then lower

vOutput := vLower
if (vText == vLower)
	vOutput := vTitle
if (vText == vTitle)
	vOutput := vUpper
if (vText == vUpper)
	vOutput := vLower

Clipboard := vOutput
SendInput ^v
Return

;==================================================

JEE_GetSelectedText(vWait=3)
{
WinGet, hWnd, ID, A
ControlGetFocus, vCtlClassNN, ahk_id %hWnd%
if (RegExReplace(vCtlClassNN, "\d", "") = "Edit")
	ControlGet, vText, Selected, , %vCtlClassNN%, ahk_id %hWnd%
else
{
	ClipSaved := ClipboardAll
	Clipboard := ""
	SendInput ^c
	ClipWait, %vWait%
	if ErrorLevel
	{
		ToolTip, ClipWait failed (%A_ThisHotkey%)
		Clipboard := ClipSaved
		ClipSaved := ""
		Sleep 1000
		ToolTip
		Exit ;terminate the thread that launched this function
	}
	vText := Clipboard
	Clipboard := ClipSaved
	ClipSaved := ""
}

Return vText
}

;==================================================
homepage | tutorials | wish list | fun threads | donate
WARNING: copy your posts/messages before hitting Submit as you may lose them due to CAPTCHA
guest3456
Posts: 3463
Joined: 09 Oct 2013, 10:31

Re: Sticky Shift

06 Mar 2017, 08:24

Helgef wrote:
guest3456 wrote: You could always just post your work-in-progress in this thread
Perhaps, but then I'd probably start poking at it again :|
I think your script would be worthwhile to post. Mine has the DOuble caps problem if you hit the keys too fast (such as almost simultaneously). I'm using Input, L1 but I still can't eliminate the problem. I think the time between the Send, {Shift down} and Send, {Shift up} is just too long. And other keypresses are getting caught. But I believe I tried Send {Shift Down}{%key%}{Shift Up} but that was causing the first char to be missed like tHis. Maybe you have an idea how to fix that and still keep it idle?

Helgef
Posts: 4709
Joined: 17 Jul 2016, 01:02
Contact:

Re: Sticky Shift

06 Mar 2017, 11:36

Hi.
guest3456 wrote:I think your script would be worthwhile to post.
I'll have to review which version is most acceptable first. I will (probably) post it later then.
guest3456 wrote:Mine has the DOuble caps problem if you hit the keys too fast (such as almost simultaneously).
I actually manage to reproduce the problem now, with your current script. But it's not that easy.
guest3456 wrote: I think the time between the Send, {Shift down} and Send, {Shift up} is just too long
That would be my guess too.
guest3456 wrote:But I believe I tried Send {Shift Down}{%key%}{Shift Up} but that was causing the first char to be missed like tHis
I think that the Input,... line (disregarding the idle waiting) takes the most time between Send, {Shift down} and Send, {Shift up}. So I guess, in both cases, your are most likely hitting two buttons while the input command is either preparing for or handling your keyboard input. So in the DOuble case, shift is down, and in the tHis case shift is not down, t is just typed out, while key:=h, hence the result. Maybe that's not readable, sorry :crazy:
guest3456 wrote:Maybe you have an idea how to fix that and still keep it idle?
Not really. :cry:
jeeswg wrote:I also use win+space sometimes to capitalise the last word:
That is nice jeeswg :thumbup:
Helgef
Posts: 4709
Joined: 17 Jul 2016, 01:02
Contact:

Re: Sticky Shift

06 Mar 2017, 18:25

@guest3456, if this version works, I think it is my best attempt, I have made it more idle, and tried to prevent the DOuble issue.

@Anyone who wants to try it, the class with examples showing how to use it are included in:
StickyKeys.ahk
(7.67 KiB) Downloaded 308 times
In summary:
  • Make any key sticky.
  • Combine sticky keys. That is, for example, you can press and release, shift then ctrl then hit a to get a shift+ctrl+a.
  • Combine sticky keys can be turned off, then turning on a sticky key turns off any sticky key previously turned on. :wtf:
Good luck.
guest3456
Posts: 3463
Joined: 09 Oct 2013, 10:31

Re: Sticky Shift

06 Mar 2017, 19:20

Helgef wrote:@guest3456, if this version works, I think it is my best attempt, I have made it more idle, and tried to prevent the DOuble issue.

@Anyone who wants to try it, the class with examples showing how to use it are included in:
StickyKeys.ahk
In summary:
  • Make any key sticky.
  • Combine sticky keys. That is, for example, you can press and release, shift then ctrl then hit a to get a shift+ctrl+a.
  • Combine sticky keys can be turned off, then turning on a sticky key turns off any sticky key previously turned on. :wtf:
Good luck.
It works well.

Minor issues:

1. I still got the DOuble issue, but much much less frequently than my script. I pretty much have to press the letters simulatenously, which is hard to do
2. When CAPS is on, the Shift should then be a lowercase letter

Helgef
Posts: 4709
Joined: 17 Jul 2016, 01:02
Contact:

Re: Sticky Shift

07 Mar 2017, 03:14

guest3456 wrote: Minor issues:
1. I still got the DOuble issue, but much much less frequently than my script. I pretty much have to press the letters simulatenously, which is hard to do
2. When CAPS is on, the Shift should then be a lowercase letter
1) :thumbdown: That is annoying. If my understanding of my own script is correct ( :lol: ), the only possibillity I can think of is that you hit the o when the script is doing,

Code: Select all

SendInput, % {Shift down}{d down}{d up}{Shift up}
and, SendInput is reverting to SendEvent, then your input is not postponed until the send is done.
So I would change, in modifiedSend(),

Code: Select all

SendInput, % prefix . "{" . A_ThisHotkey . " down}{" . A_ThisHotkey . " up}" . suffix
to

Code: Select all

;SetKeyDelay,-1,-1 ; Try with and without this.
BlockInput,Send
SendInput, % prefix . "{" . A_ThisHotkey . " down}{" . A_ThisHotkey . " up}" . suffix
BlockInput,Default
This isn't a good solution either, since you would now loose the o output, but if my therory is correct, you would instead get Duble as often as you got DOuble. A better solution would be to have BlockInput,SendPostpone, you have to guess what I mean.

2) That makes sense.

Edit: Remember that you might need to run the script as administrator in order to enable BlockInput to work.
User avatar
jeeswg
Posts: 6902
Joined: 19 Dec 2016, 01:58
Location: UK

Re: Sticky Shift

08 Mar 2017, 21:58

@Helgef Cheers.

For capitalisation I use:
- shift, letter - capitalise letter
- shift+capslock - capslock on/off
- win+space - capitalise last word (cycle: (random -->) lower --> title --> upper)
- ctrl+capslock - capitalise selection (cycle: (random -->) lower --> title --> upper)
- special hotstrings for capitalising i (with one exception: 'i.e.', and disabled on maths software e.g. Maxima CAS, TeXstudio)
- hotstrings for words e.g. 'ahk-' -> 'AutoHotkey', 'bush-' -> 'Bush', 'vtext' -> 'vText'
homepage | tutorials | wish list | fun threads | donate
WARNING: copy your posts/messages before hitting Submit as you may lose them due to CAPTCHA
guest3456
Posts: 3463
Joined: 09 Oct 2013, 10:31

Re: Sticky Shift

15 Nov 2017, 23:36

fixed a bug to allow Shift+aa=AA

ozzii
Posts: 481
Joined: 30 Oct 2013, 06:04

Re: Sticky Shift

16 Nov 2017, 03:15

jeeswg wrote: For capitalisation I use:
- shift, letter - capitalise letter
- shift+capslock - capslock on/off
- win+space - capitalise last word (cycle: (random -->) lower --> title --> upper)
- ctrl+capslock - capitalise selection (cycle: (random -->) lower --> title --> upper)
- special hotstrings for capitalising i (with one exception: 'i.e.', and disabled on maths software e.g. Maxima CAS, TeXstudio)
- hotstrings for words e.g. 'ahk-' -> 'AutoHotkey', 'bush-' -> 'Bush', 'vtext' -> 'vText'
How can I do to keep the selection active after 'ctrl+capslock'?
Because when you have to reselect the things for redoing the cycle it's not so convenient.
guest3456
Posts: 3463
Joined: 09 Oct 2013, 10:31

Re: Sticky Shift

29 Mar 2018, 07:42

Helgef wrote:and tried to prevent the DOuble issue.
i'm still using my script with my laptop, but just for reference, i'm investigating moving to a programmable mechanical keyboard, and doing this at the firmware/hardware level:

https://docs.qmk.fm
https://docs.qmk.fm/feature_advanced_ke ... -shot-keys

User avatar
BGM
Posts: 507
Joined: 20 Nov 2013, 20:56
Contact:

Re: Sticky Shift

29 Mar 2018, 11:02

I've used a compUSA SK-6200 ergonomic mechanical keyboard for decades. It was wearing out, so I actually found another one, unused and unopened, after all these years on ebay and bought it. I love it and never want to move to another keyboard, ever. I could test something if you like.
PCSsolutions
Posts: 2
Joined: 09 May 2018, 14:05

Re: Sticky Shift

14 May 2018, 01:17

Awesome script!!

You went above and beyond with the popup graphics. StickyShift will definitely help my pinky fingers from being sore toward the end of my work day.

What will help my pinkies even more is if I can totally not use them to Shift at all. Is it possible to trigger StickyShift with a tap of the ALT key while holding ALT+X should provide the normal ALT operations.

I just discover AHK and still learning its features and how to program more complex functionalities. If you can provide some suggestion on how to implement the ALT tap to Activate StickyShift, I much appreciated.

Thanks,
guest3456
Posts: 3463
Joined: 09 Oct 2013, 10:31

Re: Sticky Shift

14 May 2018, 09:22

PCSsolutions wrote: What will help my pinkies even more is if I can totally not use them to Shift at all. Is it possible to trigger StickyShift with a tap of the ALT key while holding ALT+X should provide the normal ALT operations.
I thought about this too. Using thumb for Alt keys to shift is another nice alternative. I think modifying these lines should do it:

Code: Select all

Hotkey, LShift,    Shift_Down, on
Hotkey, RShift,    Shift_Down, on
Hotkey, LShift Up, Shift_Up  , on
Hotkey, RShift Up, Shift_Up  , on

; ..... further down:

   if (ErrorLevel == "EndKey:LShift") || (ErrorLevel == "EndKey:RShift")
change those to:

Code: Select all

Hotkey, LAlt,    Shift_Down, on
Hotkey, RAlt,    Shift_Down, on
Hotkey, LAlt Up, Shift_Up  , on
Hotkey, RAlt Up, Shift_Up  , on

; ..... further down:

   if (ErrorLevel == "EndKey:LAlt") || (ErrorLevel == "EndKey:RAlt")
try it out and let me know if that works, and if it retains the normal Alt+X functionality when holding it down

kuehmaster
Posts: 3
Joined: 31 Aug 2022, 22:38

Re: Sticky Shift

31 Aug 2022, 22:40

Hi, how do I apply the sticky shift to only my left shift? What do I need to delete from your code?

Return to “Scripts and Functions (v1)”

Who is online

Users browsing this forum: hiahkforum and 153 guests