Skip to content

Instantly share code, notes, and snippets.

@fcFn
Last active July 7, 2019 12:52
Show Gist options
  • Select an option

  • Save fcFn/1c62c371d6072359bd4bb664cc456545 to your computer and use it in GitHub Desktop.

Select an option

Save fcFn/1c62c371d6072359bd4bb664cc456545 to your computer and use it in GitHub Desktop.
Layout switcher

Layout switcher

Switches between English/Russian and Hebrew/English keyboard layouts upon pressing Win+Numpad0 (NumLock has to be toggled on for the hotkey to activate). The same hotkey toggles between the two states.

Installation

  1. Download and extract the archive.
  2. Right click on both .ps1 files and check the Unblock mark in the properties.
  3. Set the Powershell execution policy to RemoteSigned. See https://docs.microsoft.com/en-us/powershell/module/microsoft.powershell.security/set-executionpolicy?view=powershell-6 for instructions.
  4. Install AutoHotkey (https://www.autohotkey.com/).
  5. Run loadhebrew.ahk.

Customization

  • You can change the hotkey to whatever you like. See documentation at https://www.autohotkey.com/docs/KeyList.htm

  • If you use different languages/layouts, follow the comments in the files and replace the languages/layouts with the ones you want.

$1 = Get-WinUserLanguageList
# Add the new language
# (for the list of language codes see:
# https://docs.microsoft.com/en-us/powershell/module/international/set-winuserlanguagelist?view=win10-ps).
#$1.Add('he')
$1.Insert(0, 'he') # Needed to switch to the chosen layout immediately after pressing the hotkey, use the line above if you don't want this
$1.RemoveAll( { $args[0].LanguageTag -clike 'ru' } ) # Remove Russian (comment out if you want to keep English/Russian AND Hebrew)
# This overrides the default order of keyboard layouts for the desired language. List of layout codes can be found behind the link above
$1[1].InputMethodTips.Clear()
#$1[1].InputMethodTips.Add("0409:A0000409")
$1[1].InputMethodTips.Add("0409:00000409")
# Use this if you have non-standard layout for the language to set it as default for its language
# (list of layouts: https://docs.microsoft.com/en-us/windows-hardware/manufacture/desktop/default-input-locales-for-windows-language-packs)
#Set-WinDefaultInputMethodOverride -InputTip "0419:00010419"
Set-WinDefaultInputMethodOverride -InputTip "040D:0002040D" #Sets the newly loaded language as the primary input method
Set-WinUserLanguageList $1 -Force
'Wraps the powershell script so no pop-ups are produced when activating the hotkey.
strFolder = Left(WScript.ScriptFullName, InStrRev(WScript.ScriptFullName, "\"))
command = "powershell.exe -nologo -command " & strFolder & WScript.Arguments(0) & ".ps1"
set shell = CreateObject("WScript.Shell")
shell.Run command,0
; Registers the hotkey and runs silently in the background. You need AutoHotkey (https://www.autohotkey.com/) installed to run the script.
; You might consider putting it in the Startup folder to load automatically on boot.
#NoTrayIcon
Toggle := "addHe"
#NumPad0::
p := A_ScriptDir "\layoutswitcherwrapper.vbs " Toggle
Run % p
if (Toggle = "addHe")
Toggle := "remHe" # The value has to correspond to the PowerShell script file names,
else Toggle := "addHe" # so if you renamed them, change this accordingly
$1 = Get-WinUserLanguageList
$1.RemoveAll( { $args[0].LanguageTag -clike 'he' } )
$1.Add('ru') # Add Russian back
# Rebuilds the order of non-standard layouts, you might not need this (but the language list might get corrupted if you do not
# do this using your own keyboard layout IDs and you will have to set your languages again vi control panel or scripting).
$1[0].InputMethodTips.Clear()
#$1[0].InputMethodTips.Add("0409:A0000409")
$1[0].InputMethodTips.Add("0409:00000409")
#$1[1].InputMethodTips.Clear()
#$1[1].InputMethodTips.Add("0419:00010419")
#$1[1].InputMethodTips.Add("0419:00000419")
#Set-WinDefaultInputMethodOverride -InputTip "0419:00010419" # Sets the non-standard layout for one of the languages I use
Set-WinDefaultInputMethodOverride -InputTip "0409:00000409"
Set-WinUserLanguageList $1 -Force
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment