How to change keyboard language layout?

Get help with using AutoHotkey and its commands and hotkeys
SmallTarzan
Posts: 1
Joined: 25 Jun 2016, 03:01
Google: Michal Tar

How to change keyboard language layout?

Post by SmallTarzan » 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: 1290
Joined: 23 Feb 2016, 19:45
Location: Denmark

Re: How to change keyboard language layout?

Post by Capn Odin » 25 Jun 2016, 06:13

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

Re: How to change keyboard language layout?

Post by bruin1953 » 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: 1456
Joined: 22 Dec 2013, 12:50

Re: How to change keyboard language layout?

Post by garry » 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
GitHub: 4GForce

Re: How to change keyboard language layout?

Post by 4GForce » 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?

Post by Heihachi88 » 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: 1
Joined: 16 Sep 2018, 04:48

Re: How to change keyboard language layout?

Post by XShayanX » 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: 1456
Joined: 22 Dec 2013, 12:50

Re: How to change keyboard language layout?

Post by garry » 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
Post Reply

Return to “Ask For Help”