1

I want to have Autoshift with AHK, I used this scritp: https://superuser.com/a/1396278/47625

; create an array/object of the keys you want shift:
Keys := ["a","b","c","d","e","f","g","h","i","j","k","l","m","n","o","p","q","r","s","t","u","v","w","x","y","z","1","2","3","4","5","6","7","8","9","0"]

; create a hotkey once for each key in this object, using a For-Loop:
For each, key in Keys
    Hotkey, $%key%, Shift_Key ; the $ prefix forces the keyboard hook to be used
return

Shift_Key:
    ThisHotkey := StrReplace(A_ThisHotkey, "$") ; remove the $ prefix 
    KeyWait, %ThisHotkey%, T0.3 ; wait max. 0.3 seconds for the key to be released
    If (ErrorLevel) ; if the command timed out (long press, the key is still pressed after 0.3 seconds)
        SendInput, +%ThisHotkey% ; "shift" it
    else
        SendInput, %ThisHotkey%
    KeyWait, %ThisHotkey% ; don't repeat the action before the key is released
return

At first this seemed to work well, there is problem however. When you type rather fast it somehow overwrites previous letters with the last letter typed:

I write within 300 miliseconds: this Result is: ssss

Is there any way how to solve this?

1

Try this:

; create an array/object of the keys you want shift:
Keys := ["a","b","c","d","e","f","g","h","i","j","k","l","m","n","o","p","q","r","s","t","u","v","w","x","y","z","1","2","3","4","5","6","7","8","9","0"]

; create a hotkey once for each key in this object, using a For-Loop:
For each, key in Keys
{   
    Hotkey, $%key%, Shift_Key ; the $ prefix forces the keyboard hook to be used
    Hotkey, ~$%key% Up, Up_Key
}
return

Shift_Key:
    ThisHotkey := StrReplace(A_ThisHotkey, "$") ; remove the $ prefix 
    If (A_PriorHotKey = "$" ThisHotKey)
    {
        Text := ThisHotkey
        StringUpper, Text, Text
        ToolTip %Text%
        KeyWait, %ThisHotkey%           
        SendInput, {BS}+%ThisHotkey% ; "shift" it
        ToolTip
    }
    else
        SendInput, %ThisHotkey%
return

Up_Key:
return
| improve this answer | |
  • Pretty good improvement, however you are unable to write two consecutive capital letters like AAA – Jarek May 5 at 17:48
  • 1
    Try the edited answer. – user3419297 May 5 at 21:24
  • Works great thank you. I guess it is not possible in AHK to make it work without backspace and initial unshifted symbol appearing, right? – Jarek May 5 at 22:10

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.