Change input language to English temporarily for a script Topic is solved

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
TsanakJim
Posts: 1
Joined: 05 Jul 2020, 09:17

Change input language to English temporarily for a script

Post by TsanakJim » 05 Jul 2020, 09:31

Hello, I made a script for a friend in cmd, but there is a problem while running it. If it runs in Greek, it doesn't work in cmd but most importantly my confidential information (password) is exposed. Is there any way possible to make a script that I can include, that temporarily changes the input language in English (without knowing the current language)? I can Alt+Shift but the problem is that autohotkey is not able to determine the current language while running. Thank you

BoBo
Posts: 6564
Joined: 13 May 2014, 17:15

Re: Change input language to English temporarily for a script

Post by BoBo » 05 Jul 2020, 14:14

"... but the problem is that autohotkey is not able to determine the current language while running."
https://autohotkey.com/board/topic/116538-detect-which-language-is-currently-on/

garry
Posts: 3740
Joined: 22 Dec 2013, 12:50

Re: Change input language to English temporarily for a script  Topic is solved

Post by garry » 05 Jul 2020, 14:42

some idea

Code: Select all

;- show selected keyboard language 
SetFormat, Integer, H
a2:= DllCall("user32.dll\GetKeyboardLayout", "UInt", ThreadId, "UInt")
msgbox,Now=%a2%
Return


;- to change the input language of the active window ( maybe first use Setdefaultkeyboardlang ) : 
;-----------------------------------------------------------------------------
^1::SetInputLang(0x0406) ; Danish
^2::SetInputLang(0x0409) ; English (USA)
^3::SetInputLang(0x0807) ; Swiss-german         ; SetInputLang(0x0411)  Japanese
^4::SetInputLang(0x0408) ; Greek

;--- modulo/toggle switch between 2 keyboard-languages 
$F4::
V++
M:=mod(V,2)
if M=1
   SetInputLang(0x0408) ; Greek
else
   SetInputLang(0x0409) ; English
sleep,1000
SetFormat, Integer, H
a2:= DllCall("user32.dll\GetKeyboardLayout", "UInt", ThreadId, "UInt")
msgbox,Now=%a2%
return

SetInputLang(Lang)
{
    WinExist("A")
    ControlGetFocus, CtrlInFocus
    PostMessage, 0x50, 0, % Lang, %CtrlInFocus%
}


;- Keyboardx Keyboardchangelanguage
;- can change keyboard , but use WIN+SPACE or alt+Shift to select ( WIN-10 ) 
;--------------------------------------------------------------------------
;- (0x0406)=danish  (0x0409)=English (USA)  (0x0411)=Japanese
;-------------------------------------------------------------
; https://docs.microsoft.com/de-de/windows/desktop/Intl/language-identifier-constants-and-strings
F6::SetDefaultKeyboardLang(0x0409)  ; english -USA
F7::SetDefaultKeyboardLang(0x0408)  ; greek el-GR
F8::SetDefaultKeyboardLang(0x0807)  ; swiss german de-CH
;-------------------------------
; https://autohotkey.com/boards/viewtopic.php?f=6&t=18519
SetDefaultKeyboardLang(LocaleID){
	Static SPI_SETDEFAULTINPUTLANG := 0x005A, SPIF_SENDWININICHANGE := 2	
	Lan := DllCall("LoadKeyboardLayout", "Str", Format("{:08x}", LocaleID), "Int", 0)
	VarSetCapacity(binaryLocaleID, 4, 0)
	NumPut(LocaleID, binaryLocaleID)
	DllCall("SystemParametersInfo", "UInt", SPI_SETDEFAULTINPUTLANG, "UInt", 0, "UPtr", &binaryLocaleID, "UInt", SPIF_SENDWININICHANGE)	
	WinGet, windows, List
	Loop % windows {
		PostMessage 0x50, 0, % Lan, , % "ahk_id " windows%A_Index%
	}
}
;===========================================================================================

gya
Posts: 25
Joined: 04 Nov 2021, 01:22

Re: Change input language to English temporarily for a script

Post by gya » 24 May 2022, 04:32

@Garry
Thank you for your script (I only tested the first part I need).
It works perfectly (Windows 10 – 64 bits — Version 21H2 (build du système d'exploitation 19044.1706).

Best regards.

PS.

;- show selected keyboard language
SetFormat, Integer, H
a2:= DllCall("user32.dll\GetKeyboardLayout", "UInt", ThreadId, "UInt")
msgbox,Now=%a2%
Return
;Keyboard Identifiers and Input Method Editors for Windows | Microsoft Docs @ https://docs.microsoft.com/en-us/windows-hardware/manufacture/desktop/windows-language-pack-default-values?view=windows-11
;- to change the input language of the active window ( maybe first use Setdefaultkeyboardlang ) :
;-----------------------------------------------------------------------------
^1::SetInputLang(0x040c) ; french
^2::SetInputLang(0x041f) ; turk
;…

Post Reply

Return to “Ask for Help (v1)”