• You are not logged in.

    Shift key problem removed with a script

    • Started by nimbostratue
    • 1 Replies:
    • Reputation: 0
    • Registered: 14-Jan-2011
    • Posts: 163

    For the last few years I have been noticing how damaging the Shift keys are  especially during programming, when they are used the most. And when I got an injury in my left hand, which has healed, I started to think seriously of finding away around hitting the Shift key. The first solution that came to my mind is replacing the tab with the Shift key, but this would only solve the problem for the left hand. The second solution, which I think is the best one is to not use the shift key at all while typing characters, most of the symbols and number keys? Is that possible? Yes it is :). To achieve this, I had to take advantage of each key individually, and the result was the to mimic in a autohotkey script the Shift behavior using multiple stroke. This is illustrated better with an example, so suppose I want to write "The successful" then I need to type "tthe successful" and that's all what I need. Thus two strokes of tt key becomes T. Now Suppose you want actually to write "tt" well no problem just type ttt. In other words the script changes two occurrences of any key called x  to to it shift state, and any three occurrences of that key to two occurrences. Thus:
    xx ==> X 
    xxx==> xx

    For the symbols I assume that the user is using a programming layout where the numbers are interchanged with symbols and the script does the same thing as mention above so.
    non-shift-state-symbol ==> shift-state-key
    ,,==> <
    ..==> >
    "" ==> '
    !! ==> 1
    @@==> 2
    .
    .
    .
    ===   ==> +=
    __     ==> -

    [[ ==>  {
    ]]  ==> }

    note here that if you type x&&y the && will not turn into 7 so you don not need to hit &&& to get &&, but if you precede the && with space then it will turn to 7 so.

    x&&y ==> x&&y
    x &&y ==> x 7y

    Ultimately the plan is to write a program similar to pkl that has the Imak layout, which has more alternation than dvorak and less same finger ratio than Colemak, combined with the behavior of the script.

    Using this script is expected to help people suffering from their wrists a lot especially if they are programmers, and it will reduce the effort on each hand by minimize the use of the shift key and keeping the hand aligned in a more natural way.

    The script is given below, but I did not test the behavior of the keys five and six as they do not work on my keyboard and the autohotkey script doesn't interact with on screen keyboard. Any way if those two keys did not work later I will modify the script. Finally, since i am new to autohotkey scripting I had to consult their forum and I would like to thank nimda for his help
    https://www.autohotkey.com/forum/topic75771.html

    and if you have any suggestion and feed back on how to improve this script then please drop a line or two :).




    Script:


    AnyEndKeys =
    ( LTrim Join
       {LWin}{RWin}{AppsKey}
       {LShift}{RShift}{LControl}{RControl}{LAlt}{RAlt}
       {F1}{F2}{F3}{F4}{F5}{F6}{F7}{F8}{F9}{F10}{F11}{F12}
       {Left}{Right}{Up}{Down}
       {Insert}{Delete}{Home}{End}{PgUp}{PgDn}
       {Space}{Tab}{Enter}{Escape}{Backspace}
       {CapsLock}{NumLock}{ScrollLock}
       {PrintScreen}{Pause}
       {Numpad0}{Numpad1}{Numpad2}{Numpad3}{Numpad4}
       {Numpad5}{Numpad6}{Numpad7}{Numpad8}{Numpad9}
       {NumpadIns}{NumpadEnd}{NumpadDown}{NumpadPgDn}{NumpadLeft}
       {NumpadClear}{NumpadRight}{NumpadHome}{NumpadUp}{NumpadPgUp}
       {NumpadDot}{NumpadDel}
       {NumpadDiv}{NumpadMult}{NumpadSub}{NumpadAdd}{NumpadEnter}
    )

    :c*:tt::
    Send T
    Input, key, l1 v, %AnyEndKeys%
    If (key == "t")
      Send {Backspace 2}tt
    return
    :c*:Tt::tt

    :c*:aa::
    Send A
    Input, key, l1 v, %AnyEndKeys%
    If (key == "a")
      Send {Backspace 2}aa
    return


    :c*:qq::
    Send Q
    Input, key, l1 v, %AnyEndKeys%
    If (key == "q")
      Send {Backspace 2}qq
    return

    :c*:ww::
    Send W
    Input, key, l1 v, %AnyEndKeys%
    If (key == "w")
      Send {Backspace 2}ww
    return

    :c*:ee::
    Send E
    Input, key, l1 v, %AnyEndKeys%
    If (key == "e")
      Send {Backspace 2}ee
    return

    :c*:rr::
    Send R
    Input, key, l1 v, %AnyEndKeys%
    If (key == "r")
      Send {Backspace 2}rr
    return

    :c*:yy::
    Send Y
    Input, key, l1 v, %AnyEndKeys%
    If (key == "y")
      Send {Backspace 2}yy
    return

    :c*:uu::
    Send U
    Input, key, l1 v, %AnyEndKeys%
    If (key == "u")
      Send {Backspace 2}uu
    return

    :c*:ii::
    Send I
    Input, key, l1 v, %AnyEndKeys%
    If (key == "i")
      Send {Backspace 2}ii
    return

    :c*:oo::
    Send O
    Input, key, l1 v, %AnyEndKeys%
    If (key == "o")
      Send {Backspace 2}oo
    return

    :c*:pp::
    Send P
    Input, key, l1 v, %AnyEndKeys%
    If (key == "p")
      Send {Backspace 2}pp
    return

    :c*:ss::
    Send S
    Input, key, l1 v, %AnyEndKeys%
    If (key == "s")
      Send {Backspace 2}ss
    return

    :c*:dd::
    Send D
    Input, key, l1 v, %AnyEndKeys%
    If (key == "d")
      Send {Backspace 2}dd
    return

    :c*:ff::
    Send F
    Input, key, l1 v, %AnyEndKeys%
    If (key == "f")
      Send {Backspace 2}ff
    return

    :c*:gg::
    Send G
    Input, key, l1 v, %AnyEndKeys%
    If (key == "g")
      Send {Backspace 2}gg
    return

    :c*:hh::
    Send H
    Input, key, l1 v, %AnyEndKeys%
    If (key == "h")
      Send {Backspace 2}hh
    return

    :c*:jj::
    Send J
    Input, key, l1 v, %AnyEndKeys%
    If (key == "j")
      Send {Backspace 2}jj
    return

    :c*:kk::
    Send K
    Input, key, l1 v, %AnyEndKeys%
    If (key == "k")
      Send {Backspace 2}kk
    return

    :c*:ll::
    Send L
    Input, key, l1 v, %AnyEndKeys%
    If (key == "l")
      Send {Backspace 2}ll
    return

    :c*:zz::
    Send Z
    Input, key, l1 v, %AnyEndKeys%
    If (key == "z")
      Send {Backspace 2}zz
    return

    :c*:xx::
    Send X
    Input, key, l1 v, %AnyEndKeys%
    If (key == "x")
      Send {Backspace 2}xx
    return

    :c*:cc::
    Send C
    Input, key, l1 v, %AnyEndKeys%
    If (key == "c")
      Send {Backspace 2}cc
    return

    :c*:vv::
    Send V
    Input, key, l1 v, %AnyEndKeys%
    If (key == "v")
      Send {Backspace 2}vv
    return

    :c*:bb::
    Send B
    Input, key, l1 v, %AnyEndKeys%
    If (key == "b")
      Send {Backspace 2}bb
    return

    :c*:nn::
    Send N
    Input, key, l1 v, %AnyEndKeys%
    If (key == "n")
      Send {Backspace 2}nn
    return

    :c*:mm::
    Send M
    Input, key, l1 v, %AnyEndKeys%
    If (key == "m")
      Send {Backspace 2}mm
    return
    :c*:Mm::mm

    :c*:,,::
    Send <
    Input, key, l1 v, %AnyEndKeys%
    If (key == ",")
      Send {Backspace 2},,
    return
    :c*:<,::,,

    :c*:..::
    Send >
    Input, key, l1 v, %AnyEndKeys%
    If (key == ".")
      Send {Backspace 2}..
    return


    :c*:!!::
    Send 1
    Input, key, l1 v, %AnyEndKeys%
    If (key == "!")
      Send {Backspace 2}{!}{!}
    return

    :*:@@::
    Send 2
    Input, key, l1 v, %AnyEndKeys%
    If (key == "@")
      Send {Backspace 2}@@
    return

    :c*:##::
    Send 3
    Input, key, l1 v, %AnyEndKeys%
    If (key == "#")
      Send {Backspace 2}{#}{#}
    return

    :c*:$$::
    Send 4
    Input, key, l1 v, %AnyEndKeys%
    If (key == "$")
      Send {Backspace 2}$$
    return

    :c*:%%::
    Send 5
    Input, key, l1 v, %AnyEndKeys%
    If (key == "%")
      Send {Backspace 2}`%`%
    return


    :c*:^^::
    Send 6
    Input, key, l1 v, %AnyEndKeys%
    If (key == "^")
      Send {Backspace 2}{^}{^}
    return

    :c*:&&::
    Send 7
    Input, key, l1 v, %AnyEndKeys%
    If (key == "&")
      Send {Backspace 2}&&
    return

    :c*:**::
    Send 8
    Input, key, l1 v, %AnyEndKeys%
    If (key == "*")
      Send {Backspace 2}**
    return

    :c*:((::
    Send 9
    Input, key, l1 v, %AnyEndKeys%
    If (key == "(")
      Send {Backspace 2}((
    return

    :c*:))::
    Send 0
    Input, key, l1 v, %AnyEndKeys%
    If (key == ")")
      Send {Backspace 2}))
    return

    :c*:__::
    Send -
    Input, key, l1 v, %AnyEndKeys%
    If (key == "_")
      Send {Backspace 2}__
    return

    :c*:===::{+}=


    :c*:""::
    Send '
    Input, key, l1 v, %AnyEndKeys%
    If (key == """")
      Send {Backspace 2}""
    return

    :c*:[[::
    Send {{}
    Input, key, l1 v, %AnyEndKeys%
    If (key == "[")
      Send {Backspace 2}[[
    return

    :c*:]]::
    Send {}}
    Input, key, l1 v, %AnyEndKeys%
    If (key == "]")
      Send {Backspace 2}]]
    return

    Offline
    • 0
    • Reputation: 0
    • Registered: 14-Jan-2011
    • Posts: 163

    Yet another nifty script code was suggested by zzzooo10, whom I would like to thank. He helped me by providing a script that did what I originally wanted. https://www.autohotkey.com/forum/topic75789.html

    the script  changes two occurrences of any key called x  to its shift state X, and any three occurrences of that key to two occurrences of it i.e xx. Thus:
    xx ==> X 
    xxx==> xx

    In contrast to the previous script this one has the same behavior for all characters and numbers keys with no exception, which is easier to remember, and it also assume the number rows is not replaced by the symbol rows and remains the same as in QWERTY.

    Finally, the script allows two behaviors:
    1- only capitalize the first letter of a text. Ex:
               tthe ==> The
    but,      success  remains as is

    2- capitalize any letter in the word
         success ==> suCeS
         succcesss ==> success

    To change the behavior you need to turn on off this line in the script
    beginning := 0 ; Change this to 1 to only capitalize the fist letter of a word.

    Here is the script:

    #NoEnv  ; Recommended for performance and compatibility with future AutoHotkey releases.
    #Persistent
    #SingleInstance, Force
    ; #NoTrayIcon

    SetBatchLines, -1
    ListLines, Off
    SetWorkingDir %A_ScriptDir%  ; Ensures a consistent starting directory.


    AnyEndKeys =
    ( LTrim Join
       {LWin}{RWin}{AppsKey}
       {LShift}{RShift}{LControl}{RControl}{LAlt}{RAlt}
       {F1}{F2}{F3}{F4}{F5}{F6}{F7}{F8}{F9}{F10}{F11}{F12}
       {Left}{Right}{Up}{Down}
       {Insert}{Delete}{Home}{End}{PgUp}{PgDn}
       {Space}{Tab}{Enter}{Escape}{Backspace}
       {CapsLock}{NumLock}{ScrollLock}
       {PrintScreen}{Pause}
       {Numpad0}{Numpad1}{Numpad2}{Numpad3}{Numpad4}
       {Numpad5}{Numpad6}{Numpad7}{Numpad8}{Numpad9}
       {NumpadIns}{NumpadEnd}{NumpadDown}{NumpadPgDn}{NumpadLeft}
       {NumpadClear}{NumpadRight}{NumpadHome}{NumpadUp}{NumpadPgUp}
       {NumpadDot}{NumpadDel}
       {NumpadDiv}{NumpadMult}{NumpadSub}{NumpadAdd}{NumpadEnter}
    )

    StringReplace, AnyEndKeys, AnyEndKeys, }, , All
    StringReplace, AnyEndKeys, AnyEndKeys, {, `, , All

    beginning := 0 ; Change this to 1 to only capitalize the fist letter of a word.
    keys := "abcdefghijklmnopqrstuvwxyz1234567890,./;'[]\-="
    CAPS .= "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"

    Loop, Parse, Keys
        Hotkey, ~%A_LoopField%, checkKeys, On
    Loop, Parse, AnyEndKeys, `,
        Hotkey, ~%A_LoopField%, checkKeys, On
    return

    checkKeys:
        key := SubStr(A_ThisHotkey, 2)
       
        Loop, Parse, CAPS, `, ; Make sure the hotkey isn't a cap.
            if (A_LoopField == key)
                return
        if (InStr(key, "shift"))
            return
        else if (key = "backspace")
        {
            word := Substr(word, 1, (StrLen(word) - 1))
            return
        }
        else if key in %AnyEndKeys% ; Make sure the hotkey isn't an endkey.
        {
            word := ""
            return
        }
        word .= key
        if (A_ThisHotkey = A_PriorHotkey) ; if hotkey was pressed twice in a row.
        {   
            if (StrLen(word) > 2) && (beginning)
                return
               
            else if (!counter)
            {
                word := Substr(word, 1, (StrLen(word) - 1))
                StringUpper, key, key
                if key is alpha
                    Send, {BackSpace 2}%key%
                else 
                    Send, {BackSpace 2}+%key%
                counter++
            }
            else
            {
                Send, {BackSpace 2}{%key% 2}
                counter := 0
            }
        }
        else
            counter := 0
    return

    Offline
    • 0