Someone from here made this script for me a few months ago. We got to what I wanted eventually after some editing, but that left some bloat behind, and that bloat has finally caught up to me bc I've been experiencing some bugs now due to this script. What I want to retain is the ability for SHIFT to work like a sticky key. That's it. I don't need WIN, ALT, or CTRL to act like sticky keys. And I don't need any GUI. Please can someone clean that stuff from this whilst preserving the SHIFT sticky key function?
Edit- or an easy way to toggle if I want to include CTRL or ALT would be even better
Requires AutoHotkey v2.0
StickyKeys('Shift') StickyKeys.ShowOverlay := false
StickyKeys(mods*) { static trackedKeys := Map(), ih, dh, overlay, otherKeyPressed := 0, _ := Init()
if ih.InProgress
ih.Stop()
if dh.InProgress
dh.Stop()
for k in trackedKeys {
Hotkey '~*' k, 'Off'
Hotkey '~*' k ' Up', 'Off'
}
trackedKeys.Clear()
ih.KeyOpt('{All}', 'NS'), dh.KeyOpt('{All}', 'N')
for k in mods {
keyName := GetKeyName(k)
trackedKeys[keyName] := {isSticky: false, isDown: false}
if keyName ~= '^(Control|Shift|Alt)$' {
keys := '{L' keyName '}{R' keyName '}'
ih.KeyOpt(keys, '-NS')
dh.KeyOpt(keys, '-N')
} else {
ih.KeyOpt('{' keyName '}', '-NS')
dh.KeyOpt('{' keyName '}', '-N')
}
Hotkey '~*' keyName, OnHotkeyDown.Bind(keyName), 'On'
Hotkey '~*' keyName ' Up', OnHotkeyUp.Bind(keyName), 'On'
}
Init() {
if !StickyKeys.HasProp('ShowOverlay')
StickyKeys.ShowOverlay := true
ih := InputHook('L0 I')
ih.OnKeyDown := OnKeyDown
dh := InputHook('L0 V I')
dh.OnKeyDown := (dh, *) => (dh.Stop(), otherKeyPressed := 1)
overlay := Gui('+ToolWindow -Caption +AlwaysOnTop +E0x20 -DPIScale')
overlay.BackColor := '0D1117'
overlay.SetFont('s12 Bold cC9D1D9', 'Consolas')
overlay.AddText('vText')
WinSetTransparent(255, overlay)
return 1
}
OnHotkeyDown(keyName, *) {
if keyName ~= 'LWin|RWin'
Send '{Blind}{VKE8}'
trackedKeys[keyName].isDown := true
downCount := 0
for k, v in trackedKeys
downCount += v.isDown
if downCount = 1 {
otherKeyPressed := 0
dh.Start()
}
}
OnHotkeyUp(keyName, *) {
dh.Stop()
trackedKeys[keyName].isDown := false
if !otherKeyPressed
toggleStickyKey(keyName)
}
ToggleStickyKey(keyName) {
trackedKeys[keyname].isSticky ^= 1
stickyCount := 0
for k, v in trackedKeys
stickyCount += v.isSticky
if stickyCount > 0 {
ih.Start()
if StickyKeys.ShowOverlay
UpdateGui()
} else {
ih.Stop()
overlay.Hide()
}
}
OnKeyDown(ih, vk, sc) {
ih.Stop()
overlay.Hide()
keyName := GetKeyName(Format('VK{:X}SC{:X}', vk, sc))
pressKeys := '{' keyName '}'
for k, v in trackedKeys {
if v.isSticky {
v.isSticky := false
pressKeys := '{' k ' down}' pressKeys '{' k ' up}'
}
}
Send '{Blind}' pressKeys
}
UpdateGui() {
text := ''
for k, v in trackedKeys {
if v.isSticky
text .= k ' + '
}
text := StrReplace(SubStr(text, 1, -3), 'Control', 'Ctrl')
overlay['Text'].Value := text
size := TextWidth(overlay['Text'], text)
overlay['Text'].Move(,, size.Width, size.Height)
xPos := A_ScreenWidth - (size.Width + overlay.MarginX*2 + 50)
yPos := A_ScreenHeight - (size.Height + overlay.MarginY*2 + 150)
overlay.Show('NA AutoSize x' xPos ' y' yPos)
}
TextWidth(ctrl, text) {
hdc := DllCall('GetDC', 'ptr', ctrl.Hwnd, 'ptr')
hFont := SendMessage(0x31, 0, 0, ctrl.Hwnd) ; WM_GETFONT
oldFont := DllCall('SelectObject', 'ptr', hdc, 'ptr', hFont, 'ptr')
size := Buffer(8)
DllCall('GetTextExtentPoint32', 'ptr', hdc, 'str', text, 'int', StrLen(text), 'ptr', size)
width := NumGet(size, 0, 'int')
height := NumGet(size, 4, 'int')
DllCall('SelectObject', 'ptr', hdc, 'ptr', oldFont)
DllCall('ReleaseDC', 'ptr', ctrl.Hwnd, 'ptr', hdc)
return {Width:width, Height:height}
}
}