• You are not logged in.
  • Index
  • Technical
  • alternative keyboard shortcut for switching layouts (Win XP)

    alternative keyboard shortcut for switching layouts (Win XP)

    • Started by Vibovit
    • 13 Replies:
    • Reputation: 0
    • Registered: 11-Oct-2009
    • Posts: 5

    hi all! a quick technical question

    is there any way to modify the default OS shortcut for switching between active keyboard layouts?

    under Windows XP the user is limited to either Ctrl+Shift or Alt+Shift, both rather inconvenient (I tend to strike them by accident every now and then)

    i wish i could assign this function to Scroll Lock (putting it to some use finally)

    i thought about remapping keys, but registry-based remapping (SharpKeys) only allows for remapping single keys to other single keys (hence you cannot remap Scroll Lock to Ctrl+Shift)

    alternative solutions? some scripts maybe? like AutoHotKey? but how?

    i know there's plenty of programmers among Colemak users... :))) i'd appreciate any advice!

    cheers

    Last edited by Vibovit (11-Oct-2009 02:08:32)
    Offline
    • 0
    • Reputation: 23
    • From: Belgium
    • Registered: 26-Feb-2008
    • Posts: 482

    With PKL you can freely choose what key or key combination toggles between layouts, or suspends pkl.

    I have in my pkl.ini "changeLayoutHotkey = LCtrl & RCtrl,RCtrl & LCtrl" to change layouts by pressing both Control keys (in any order), to mimic what I have on X11.  I assume you can use anything here including Scroll Lock.

    If you use only one layout you can similarly set "suspendHotkey" to enable/disable it.

    Offline
    • 0
    • Reputation: 0
    • Registered: 11-Oct-2009
    • Posts: 5

    I actually use 3 layouts :) apart from Colemak and default QWERTY (which I still need, at least until I get proficient with Colemak) I use my customized QWERTZ national layout for writing in my native language, and that layout is not managed by PKL.

    From what I read, PKL bases on AutoHotKey scripts anyway, so I guess that instead of duplicating the layout (which to me seems a bit of an "overkill" here) one could simply remap Scroll Lock to Alt+Shift with some simple .ahk script. The question is, how? I tried

    ScrollLock::!+

    but it doesn't work.

    Come to think of it, perhaps it's quite stupid of me not to ask about this on AutoHotKey's own forum actually :)
    I'll report back on my findings

    Last edited by Vibovit (11-Oct-2009 18:29:45)
    Offline
    • 0
    • Reputation: 0
    • Registered: 11-Oct-2009
    • Posts: 5

    okay! it took me a while but I've solved the mystery

    ScrollLock::Send {Alt down}{Shift down}{Shift up}{Alt up}

    - remaps Scroll Lock (and probably any other key), to Alt+Shift

    hope it will be helpful for someone

    Offline
    • 0
    • Reputation: 23
    • From: Belgium
    • Registered: 26-Feb-2008
    • Posts: 482

    But this way you may still hit Alt-Shift and switch layouts by accident. :-)

    Offline
    • 0
    • Reputation: 214
    • From: Viken, Norway
    • Registered: 13-Dec-2006
    • Posts: 5,364

    Search the Autohotkey forums - I seem to remember a layout-switching code snippet a while back. I think you have to send some system message(s) but I can't remember which right now. Sending Shift+Alt is a poor solution as ghen pointed out.

    PKL can easily handle as many layouts as you'd like. I don't consider it overkill at all since you get the 'Extend' functionality and portability added!

    The PKL syntax for multiple layout definitions in pkl.ini is:
    in [pkl]
    layout = layout1:DisplayedName1,layout2:DisplayedName2,layout3:DisplayedName3
    ...etc

    *** Learn Colemak in 2–5 steps with Tarmak! ***
    *** Check out my Big Bag of Keyboard Tricks for Win/Linux/TMK... ***

    Offline
    • 0
    • Reputation: 0
    • Registered: 17-Mar-2008
    • Posts: 192

    If you're already using AutoHotKey, why not just implement Colemak in it? That way you won't have to switch layouts, you can just add hotkeys to disable/enable Colemak or whatever else you wish to do.

    Offline
    • 0
    • Reputation: 0
    • Registered: 11-Oct-2009
    • Posts: 5
    DreymaR said:

    Search the Autohotkey forums - I seem to remember a layout-switching code snippet a while back. I think you have to send some system message(s) but I can't remember which right now.

    If you happened to come across it, I would definitely be obliged! The (still-not-that-great) solution I managed to find there was buried down in their change log from 2004 I think :)

    tomlu said:

    If you're already using AutoHotKey, why not just implement Colemak in it? That way you won't have to switch layouts, you can just add hotkeys to disable/enable Colemak or whatever else you wish to do.

    Hmmm and how can I do this?

    And what about my custom QWERTZ layout with funny characters. (I created it using Microsoft Keyboard Layout). Can I somehow import it into AutoHotkeys? Does AHK at least offer some tool for re-creating it?

    Offline
    • 0
    • Reputation: 23
    • From: Belgium
    • Registered: 26-Feb-2008
    • Posts: 482
    Vibovit said:

    And what about my custom QWERTZ layout with funny characters. (I created it using Microsoft Keyboard Layout). Can I somehow import it into AutoHotkeys? Does AHK at least offer some tool for re-creating it?

    I don't know about AHK, but with PKL it is possible.  I created my own Russian layout (Rulemak) with it, and I'm using PKL to switch between Colemak, Rulemak, and Qwerty:

    layout = Colemak,Rulemak
    changeLayoutHotkey = LCtrl & RCtrl,RCtrl & LCtrl
    suspendHotkey = LAlt & RAlt,RAlt & LAlt

    So I switch between Colemak & Rulemak by pressing both Control keys, and switch back to Qwerty (disable PKL) by pressing both Alt keys.

    With PKL, each layout is defined in a separate layout.ini file, which is easy to edit.  The Colemak layout ships with PKL (from Sourceforge), and you can find my Rulemak layout here as another example.

    Offline
    • 0
    • Reputation: 0
    • Registered: 17-Mar-2008
    • Posts: 192

    I'm switching between Swedish and Colemak, with additional keyboard shortcuts for disable and reload (if I've edited the script).

    In addition, I have a layer for programming keys and another transpose layer for arrow keys. If you don't need those layers the autohotkey code is even easier.

    Here's my script. You'd probably need to know how to code to make use of it.

    #SingleInstance force
    #HotKeyInterval 2000
    #MaxHotkeysPerInterval 200
    #NoEnv
    
    SendMode input
    SetTitleMatchMode RegEx
    altgrcount := 0
    transposed := 0
    transposed_occured := 0
    suspended := 0
    english := 1
    
    menu_swedish = &Swedish (Alt+F6)
    menu_suspend = &Suspend (Alt+F7)
    menu_reload = &Reload (Alt+F8)
    
    Menu Tray, Add, %menu_swedish%, k_Swedish
    Menu Tray, Add, %menu_suspend%, k_MenuSuspend
    Menu Tray, Add, %menu_reload%, k_MenuReload
    Menu Tray, Add, &Exit, k_MenuExit
    Menu Tray, Icon, on.ico
    ;Menu Tray, NoStandard
    
    ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
    ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
    
    
    Map(normal, shifted, altgr, transpose, is_letter) 
    {
        global altgrcount
        global transposed
        global transposed_occured
    
        if altgrcount
            sendinput {blind}%altgr%
        else if transposed
        {
            transposed_occured := 1
            sendinput {blind}%transpose%
        }
        else if getkeystate("Shift")
            if is_letter
                sendinput {blind}%shifted%
            else
                sendinput %shifted%
        else if (caps_sensitive and getkeystate("Capslock", "T"))
            sendinput {blind}%shifted%
        else
            sendinput {blind}%normal%
    } 
    
    MapLetter(normal, altgr, transpose) 
    {
        Map(normal, normal, altgr, transpose, true)
    }
    MapChar(normal, shifted, altgr, transpose) 
    {
        Map(normal, shifted, altgr, transpose, false) 
    }
    MapLang(engnorm, engshift, swenorm, sweshift, altgr, transpose, is_letter)
    {
        global english
        if english
            Map(engnorm, engshift, altgr, transpose, is_letter)
        else
            Map(swenorm, sweshift, altgr, transpose, true)
    }
    
    IncAltGr()
    {
        global altgrcount
        altgrcount := altgrcount + 1
    }
    DecAltGr()
    {
        global altgrcount
        altgrcount := altgrcount - 1
    }
    SetTransposed(val)
    {
        global transposed
        transposed := val
    }
    
    $*q::MapLetter("q", "", "")    ; Q
    $*w::MapLetter("w", "$", "")   ; W
    $*e::MapLetter("f", "{{}", "") ; E
    $*r::MapLetter("p", "{}}", "") ; R
    $*t::MapLetter("g", "\", "")   ; T
    
    $*a::MapLetter("a", "@", "")   ; A
    $*s::MapLetter("r", "*", "")   ; S
    $*d::MapLetter("s", ":", "")   ; D
    $*f::MapLetter("t", "/", "")   ; F
    $*g::MapLetter("d", """", "")  ; G
    
    $*x::MapLetter("x", "~", "")   ; X
    $*c::MapLetter("c", "|", "")   ; C
    $*v::MapLetter("v", "&", "")   ; V
    $*b::MapLetter("b", "{#}", "") ; B
    
    $*y::MapLetter("j", "1", "")   ; Y
    $*u::MapLetter("l", "{+}", "") ; U
    $*i::MapLetter("u", "[", "{up}")   ; I
    $*o::MapLetter("y", "]", "")   ; O
    $*p::MapLang("z", "z", "ö", "Ö", "", "", true)    ; P
    $*sc01a::MapLang("[", "{{}", "å", "Å", "", "", false) ; [
    
    $*h::MapLetter("h", "0", "{backspace}")  ; H
    $*j::MapLetter("n", "=", "{left}")  ; J
    $*k::MapLetter("e", "(", "{down}")  ; K
    $*l::MapLetter("i", ")", "{right}")  ; L
    $*sc027::MapLetter("o", ";", "{return}")  ; ;
    $*sc028::MapLang("'", """", "ä", "Ä", "{!}", "", false) ; '
    
    $*n::MapLetter("k", "_", "")  ; N
    $*m::MapLetter("m", "-", "{appskey}")  ; M
    $*sc033::MapChar(",", "?", "<", "")   ; ,
    $*sc034::MapChar(".", "{!}", ">", "") ; .
    
    ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
    ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
    
    ; Map the altgr and an extra shift
    
    ; Z key
    $sc02c::
    IncAltGr()
    KeyWait sc02c
    DecAltGr()
    return
    
    ; / key
    $sc035::
    IncAltGr()
    KeyWait sc035
    DecAltGr()
    return
    
    ; \ key
    $sc02b::
    sendinput {RShift down}
    KeyWait sc02b
    sendinput {RShift up}
    return
    
    ; Caps lock key
    $*sc03a::
    transposed := 1
    KeyWait sc03a
    transposed := 0
    if (not transposed_occured) 
        ToggleCaps()
    transposed_occured := 0
    return
    
    ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
    ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
    
    ToggleCaps()
    {
        GetKeyState, state, CapsLock, T ;  D if CapsLock is ON or U otherwise.
        if state = D
            SetCapsLockState, off
        else
            SetCapsLockState, on
    }
    
    CapsOff()
    {
        GetKeyState, state, CapsLock, T ;  D if CapsLock is ON or U otherwise.
        if state = D
            SetCapsLockState, off
    } 
    
    ; Apps, escape -> caps off + escape
    $Esc::
    AppsKey::
    CapsOff()
    sendinput {Esc}
    return 
    
    ; App switching (set to work with alt tab replacement)
    End::
    RAlt::
    sendinput #{F12}
    return
    +End::
    sendinput #{F11}
    return
    
    ; Miscellaneous
    Shift & backspace::sendinput ^{backspace}
    
    ; App launch
    PgUp::sendinput #{space}
    
    ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
    ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
    
    ; Window functions
    
    ; Win kill
    PgDn::
    $#n::
    $#w::WinClose, A
    
    ; Switch to desktop
    $#h::
    sendinput {blind}d
    return
    
    ; Win maximise
    $#m::
    winget, max, MinMax, A
    if max = 1
        WinRestore, A
    else
        WinMaximize, A
    return
    
    ;$#k::
    ;run ..\FreeCommander\FreeCommander.exe,,,pid
    ;WinWait, ahk_pid %pid%
    ;WinActivate
    ;return
    
    
    ; End of auto-execute section
    return
    
    ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
    ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
    
    ; Menu functions
    
    !F6::
    k_Swedish:
    english := 1 - english
    Menu Tray, ToggleCheck, %menu_swedish%
    return
    
    !F7::
    k_MenuSuspend:
    Suspend
    if suspended
        Menu Tray, Icon, on.ico
    else
        Menu Tray, Icon, off.ico, 1, 1
    suspended := 1 - suspended
    Menu Tray, ToggleCheck, %menu_suspend%
    return
    
    !F8::
    k_MenuReload:
    Reload
    return
    
    k_MenuExit:
    ExitApp
    return
    Offline
    • 0
    • Reputation: 214
    • From: Viken, Norway
    • Registered: 13-Dec-2006
    • Posts: 5,364

    Found it!!!

    Locale=00000409   ; for example - this is the English locale code
    DllCall("SendMessage", UInt, WinActive("A"), UInt, 80, UInt, 1,UInt, DllCall("LoadKeyboardLayout", Str, %Locale%, UInt, 257))

    from the Autohotkey forums.

    I hope you understand how you might adapt that to your own uses?

    *** Learn Colemak in 2–5 steps with Tarmak! ***
    *** Check out my Big Bag of Keyboard Tricks for Win/Linux/TMK... ***

    Offline
    • 0
    • Reputation: 23
    • From: Belgium
    • Registered: 26-Feb-2008
    • Posts: 482

    Now that looks intuitive. :-)

    Offline
    • 0
    • Reputation: 214
    • From: Viken, Norway
    • Registered: 13-Dec-2006
    • Posts: 5,364

    You're from a country with an interesting language and must have built your own OS from what I gather. Surely you aren't going to be a crybaby over a cute little SendMessage?  :D

    *** Learn Colemak in 2–5 steps with Tarmak! ***
    *** Check out my Big Bag of Keyboard Tricks for Win/Linux/TMK... ***

    Offline
    • 0
    • Reputation: 0
    • Registered: 11-Oct-2009
    • Posts: 5

    Thanks so much guys! I need a while to get down to it. I'll try to get it working over the weekend

    Offline
    • 0
      • Index
      • Technical
      • alternative keyboard shortcut for switching layouts (Win XP)