How to change keyboard language layout?

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
SmallTarzan
Posts: 1
Joined: 25 Jun 2016, 03:01

How to change keyboard language layout?

25 Jun 2016, 03:06

Hi,

I am a newbie in .AHK.
Can someone help?

I need a script that makes a shortcut to change keyboard layout, for ex. from ENG to SLK or so.
From default ALT + Shift to something else, for ex. LCTRL + LSHIFT and RCTRL + RSHIFT.

I would appreciate any help!

Thanks.
User avatar
Capn Odin
Posts: 1352
Joined: 23 Feb 2016, 19:45
Location: Denmark
Contact:

Re: How to change keyboard language layout?

25 Jun 2016, 06:13

Please excuse my spelling I am dyslexic.
bruin1953
Posts: 9
Joined: 22 Jan 2015, 10:27

Re: How to change keyboard language layout?

13 Feb 2017, 17:01

For many years, I have used the plain Capslock to change language with no problems. The key is handy and useless! Besides, if you ever need to Capslock, use the key with Shift.

Code: Select all

Capslock::
     Send, {Alt Down}{Shift Down}{Shift Up}{Alt Up}
     SoundBeep 999, 1
return
garry
Posts: 3770
Joined: 22 Dec 2013, 12:50

Re: How to change keyboard language layout?

13 Feb 2017, 17:35

thank you Capn Odin , some links
EDIT : added function
;- in WINDOWS-10 maybe use key WIN+SPACE
;----------------------------------------------------------
; https://autohotkey.com/docs/misc/Languages.htm ---
; http://www.science.co.il/language/locale-codes.asp

; https://msdn.microsoft.com/en-us/librar ... 85%29.aspx
; https://msdn.microsoft.com/en-us/librar ... 85%29.aspx
;--------------------------------------------------------------------

Code: Select all

;-  toggle F4 > russian or english-US
$F4::
V++
M:=mod(V,2)
if M=1
   SetDefaultKeyboard(0x0419) ; Russian
else
   SetDefaultKeyboard(0x0409) ; english-US
return

SetDefaultKeyboard(LocaleID){
	Global
	SPI_SETDEFAULTINPUTLANG := 0x005A
	SPIF_SENDWININICHANGE := 2
	Lan := DllCall("LoadKeyboardLayout", "Str", Format("{:08x}", LocaleID), "Int", 0)
	VarSetCapacity(Lan%LocaleID%, 4, 0)
	NumPut(LocaleID, Lan%LocaleID%)
	DllCall("SystemParametersInfo", "UInt", SPI_SETDEFAULTINPUTLANG, "UInt", 0, "UPtr", &Lan%LocaleID%, "UInt", SPIF_SENDWININICHANGE)
	WinGet, windows, List
	Loop %windows% {
		PostMessage 0x50, 0, %Lan%, , % "ahk_id " windows%A_Index%
	}
}
return
Last edited by garry on 16 Sep 2018, 05:23, edited 1 time in total.
4GForce
Posts: 553
Joined: 25 Jan 2017, 03:18
Contact:

Re: How to change keyboard language layout?

14 Feb 2017, 15:36

FYI:

Alt+Shift switches between keyboard layouts
Ctrl+Shift is already default to switch keyboard languages within a layout
This all depends on how you've set it up.
And you can set specific shortcuts directly in windows.
Spoiler
Heihachi88
Posts: 29
Joined: 09 Aug 2018, 11:24

Re: How to change keyboard language layout?

09 Aug 2018, 21:37

Guys, have you tried to open (Win+S or Win+A) then switch language? For me it's not working. Maybe we can correct the scripts in order to make it work?
XShayanX
Posts: 83
Joined: 16 Sep 2018, 04:48

Re: How to change keyboard language layout?

16 Sep 2018, 04:52

garry wrote:thank you Capn Odin , some links
;- in WINDOWS-10 maybe use key WIN+SPACE
;----------------------------------------------------------
; https://autohotkey.com/docs/misc/Languages.htm ---
; http://www.science.co.il/language/locale-codes.asp

; https://msdn.microsoft.com/en-us/librar ... 85%29.aspx
; https://msdn.microsoft.com/en-us/librar ... 85%29.aspx
;--------------------------------------------------------------------

Code: Select all

;-  toggle F4 > russian or english-US
$F4::
V++
M:=mod(V,2)
if M=1
   SetDefaultKeyboard(0x0419) ; Russian
else
   SetDefaultKeyboard(0x0409) ; english-US
return
Hi, I get this error:
Call to nonexistent function
Please help!
garry
Posts: 3770
Joined: 22 Dec 2013, 12:50

Re: How to change keyboard language layout?

16 Sep 2018, 05:23

sorry , missing function

Code: Select all

;-  toggle F4 > swiss-german or english-US
$F4::
V++
M:=mod(V,2)
if M=1
   {
   SetDefaultKeyboard(0x0807)  ;- swiss german
   ;SetDefaultKeyboard(0x0419) ; Russian
   }
else
   SetDefaultKeyboard(0x0409) ; english-US
return
SetDefaultKeyboard(LocaleID){
	Global
	SPI_SETDEFAULTINPUTLANG := 0x005A
	SPIF_SENDWININICHANGE := 2
	Lan := DllCall("LoadKeyboardLayout", "Str", Format("{:08x}", LocaleID), "Int", 0)
	VarSetCapacity(Lan%LocaleID%, 4, 0)
	NumPut(LocaleID, Lan%LocaleID%)
	DllCall("SystemParametersInfo", "UInt", SPI_SETDEFAULTINPUTLANG, "UInt", 0, "UPtr", &Lan%LocaleID%, "UInt", SPIF_SENDWININICHANGE)
	WinGet, windows, List
	Loop %windows% {
		PostMessage 0x50, 0, %Lan%, , % "ahk_id " windows%A_Index%
	}
}
return
2nd example :

Code: Select all

;- keyboardx Capn Odin
;https://autohotkey.com/boards/viewtopic.php?f=6&t=18519
^0::SetDefaultKeyboard(0x0807) ; swiss-german
^1::SetDefaultKeyboard(0x0406) ; Danish
^2::SetDefaultKeyboard(0x0409) ; English (USA)
^3::SetDefaultKeyboard(0x0411) ; Japanese
^4::SetDefaultKeyboard(0x0408) ; Greek
return

SetDefaultKeyboard(LocaleID){
	Global
	SPI_SETDEFAULTINPUTLANG := 0x005A
	SPIF_SENDWININICHANGE := 2
	Lan := DllCall("LoadKeyboardLayout", "Str", Format("{:08x}", LocaleID), "Int", 0)
	VarSetCapacity(Lan%LocaleID%, 4, 0)
	NumPut(LocaleID, Lan%LocaleID%)
	DllCall("SystemParametersInfo", "UInt", SPI_SETDEFAULTINPUTLANG, "UInt", 0, "UPtr", &Lan%LocaleID%, "UInt", SPIF_SENDWININICHANGE)
	WinGet, windows, List
	Loop %windows% {
		PostMessage 0x50, 0, %Lan%, , % "ahk_id " windows%A_Index%
	}
}
return
Anomaly
Posts: 1
Joined: 03 Feb 2023, 07:33

Re: How to change keyboard language layout?

03 Feb 2023, 07:45

garry wrote:
13 Feb 2017, 17:35

Code: Select all

;-  toggle F4 > russian or english-US
$F4::
V++
M:=mod(V,2)
if M=1
   SetDefaultKeyboard(0x0419) ; Russian
else
   SetDefaultKeyboard(0x0409) ; english-US
return

SetDefaultKeyboard(LocaleID){
	Global
	SPI_SETDEFAULTINPUTLANG := 0x005A
	SPIF_SENDWININICHANGE := 2
	Lan := DllCall("LoadKeyboardLayout", "Str", Format("{:08x}", LocaleID), "Int", 0)
	VarSetCapacity(Lan%LocaleID%, 4, 0)
	NumPut(LocaleID, Lan%LocaleID%)
	DllCall("SystemParametersInfo", "UInt", SPI_SETDEFAULTINPUTLANG, "UInt", 0, "UPtr", &Lan%LocaleID%, "UInt", SPIF_SENDWININICHANGE)
	WinGet, windows, List
	Loop %windows% {
		PostMessage 0x50, 0, %Lan%, , % "ahk_id " windows%A_Index%
	}
}
return
Hello, i desperately need the same script for AutoHotkey v2. :-|

Ideally that would assign Ctrl+Shift to change the input language.
(yes, i know it can be assigned in Windows settings)

Return to “Ask for Help (v1)”

Who is online

Users browsing this forum: Araphen and 417 guests