Exclude an input language from Alt+Shift switching cycle on Windows 10

4

1

I have 3 languages on my system: english, russian and japanese. But I only want to be able to Alt+Shift between english and russian. Is there a way to do it in W10?

This question doesn't apply here, because it doesn't work on W10.

Liburia

Posted 2017-10-28T04:25:00.560

Reputation: 41

Can you explain *why* Exclude an input language from Alt+Shift / Ctrl+Shift switching cycle on Windows doesn’t seem to apply here?  It looks like an exact duplicate.

– Scott – 2017-10-28T05:00:49.443

@Scott It's for Windows 7, I can't find any way to replicate the answers on W10 from that question. – Liburia – 2017-10-28T05:03:34.967

1OK,  [edit] your question to explain that. – Scott – 2017-10-28T05:10:42.683

Answers

2

Follow this steps:

  1. Install AutoHotkey.
  2. Create a text file and paste the following text:
; This scripts changes the functionality of Shift + Alt from "switch keyboard layout"
; to "change to previous layout".
; this is usefull when you have more than 2 keyboard layouts and want to switch between 
; only 2 of them.

#NoEnv  ; Recommended for performance and compatibility with future AutoHotkey releases.
SendMode Input  ; Recommended for new scripts due to its superior speed and reliability.
SetWorkingDir %A_ScriptDir%  ; Ensures a consistent starting directory.

LAlt & LShift::send, #^{space down}{space up}
  1. Save and rename the file with .ahk extension (e.g. "Exclude Extra Keyboard Layouts.ahk")
  2. Double click to run the script. Now Alt+Shift should switch only between the first two keyboard layouts.

If you are satisfied you can compile the script (right click -> compile) to create the .exe file. then move the .exe or .ahk file to the start-up folder (open RUN and type "shell:startup" without quotes).

Extra Notes:

  • If you copy the .exe file you don't need AutoHotkey anymore so you can uninstall it.
  • If you copy the .ahk script file you must not uninstall AutoHotkey.
  • This post solves a somewhat similar problem, helped to come up with the idea.

Ewindar

Posted 2017-10-28T04:25:00.560

Reputation: 21

0

I suggest probably slightly better approach with same autohotkey solution.

Instead of switching to previous layout (which might be the third), better to disable native Alt+Shift cycling hotkey and make way for own layout switching logic.

disable example

And use following script, maybe with desired adjustments:

#SingleInstance force
SendMode Input

; Cycled list of language ids
; refer to https://docs.microsoft.com/en-us/windows/win32/intl/language-identifiers
; and https://docs.microsoft.com/en-us/windows/win32/intl/language-identifier-constants-and-strings
; for finding out correct values
; in this case 0x409 means standard US English, and 0x419 means standard Russian
AltShiftLangs := [0x0409, 0x0419]

; 0x411 means japanese IME
CtrlAltLang := 0x0411

; This returns currently active language id
GetKeyboardLayout() {
  WinGet, WinID,, A
  ThreadID:=DllCall("GetWindowThreadProcessId", "UInt", WinID, "UInt", 0)
  return DllCall("GetKeyboardLayout", "UInt", ThreadID, "UInt") & 0xFFFF
}

; This sends request to change system language to lang argument
SetKeyboardLayout(lang) {
  PostMessage, 0x50,, lang,, A
}

; This returns 0-based index of Value in Arr
IndexOf(Arr, Value) {
  Loop % Arr.Length()
    if Arr[A_Index] == Value {
      return A_Index-1
    }
  return -1
}

; This sets language based on current system lanuage and next value by index in Arr
; If current language is not found, it sets system to first language from Arr
SetNextLanguage(Arr) {
  lang := GetKeyboardLayout()
  idx := IndexOf(Arr, lang)
  if (idx < 0) {
    SetKeyboardLayout(Arr[1])
    return
  }
  nextIdx := mod(idx+1, Arr.Length())
  next := Arr[nextIdx+1]
  SetKeyboardLayout(next)
}

; Alt+Shift hotkey - cycle between AltShiftLangs
LAlt & LShift::
SetNextLanguage(AltShiftLangs)
return

; Ctrl+Alt hotkey - switch directly to isolated CtrlAltLang
LCtrl & LAlt::
SetKeyboardLayout(CtrlAltLang)
return

Alexander Tumin

Posted 2017-10-28T04:25:00.560

Reputation: 111