if current keyboard layout is english then

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
Eguy

if current keyboard layout is english then

25 Jun 2016, 16:05

hello i want my script detect the current keyboard layout and if it is English then suspend script.So whenever i change to English i want my script to be suspended(stop work)
i want a constant check for this.if current keyboard layout isn't English then do not suspend.
User avatar
Capn Odin
Posts: 1352
Joined: 23 Feb 2016, 19:45
Location: Denmark
Contact:

Re: if current keyboard layout is english then

25 Jun 2016, 16:09

Try this.

Code: Select all

#Persistent

English := 0x4090409

SetTimer, CheckLang, 200

CheckLang:
	if(English = Format("0x{:x}", DllCall("GetKeyboardLayout", "Int", DllCall("GetWindowThreadProcessId", "Int", WinActive("A"), "Int", 0)))){
		Suspend, On
	} else {
		Suspend, Off
	}
return
Edit: Corrected an error.
Please excuse my spelling I am dyslexic.
Eguy

Re: if current keyboard layout is english then

26 Jun 2016, 07:48

it worked but suspend it doesn't really work and I don't know why.it goes to suspend mode fine but hotkeys etc are still working.suspend works only if I click on tray icon..same happens with suspend off again it doesn't start my script its still like in suspended mode.May I could achieve it with postmessage.I also tried with pause same thing happens.
But the code works great.not the way I wanted to but it does what I asked.Thanks
User avatar
Capn Odin
Posts: 1352
Joined: 23 Feb 2016, 19:45
Location: Denmark
Contact:

Re: if current keyboard layout is english then

26 Jun 2016, 10:22

Eguy wrote:it worked but suspend it doesn't really work and I don't know why.it goes to suspend mode fine but hotkeys etc are still working.suspend works only if I click on tray icon..same happens with suspend off again it doesn't start my script its still like in suspended mode.May I could achieve it with postmessage.I also tried with pause same thing happens.
But the code works great.not the way I wanted to but it does what I asked.Thanks
Could you explain how you wanted it to work ? for instance in what way does Suspend not do what you wanted ?
Please excuse my spelling I am dyslexic.
Eguy

Re: if current keyboard layout is english then

26 Jun 2016, 11:54

well I want to make my script stop working including my hotstrings and hotkeys etc and some if statements when the keyboard layout is English.And if I cgange keyboard layout to another language continue script.Thats it.I thought the script you gave me was ok but for some reason it doesn't update the state of the script only if I click on the tray icon.I meant it goes to suspended mode which means that my current keyboard layout is English but script continue working even in suspend mode..
User avatar
Capn Odin
Posts: 1352
Joined: 23 Feb 2016, 19:45
Location: Denmark
Contact:

Re: if current keyboard layout is english then

26 Jun 2016, 12:00

Eguy wrote:well I want to make my script stop working including my hotstrings and hotkeys etc and some if statements when the keyboard layout is English.And if I cgange keyboard layout to another language continue script.Thats it.I thought the script you gave me was ok but for some reason it doesn't update the state of the script only if I click on the tray icon.I meant it goes to suspended mode which means that my current keyboard layout is English but script continue working even in suspend mode..
Have you tried combining Suspend and Pause ?

Code: Select all

#Persistent
 
English := 0x4090409
 
SetTimer, CheckLang, 200
 
CheckLang:
	if(English = Format("0x{:x}", DllCall("GetKeyboardLayout", "Int", DllCall("GetWindowThreadProcessId", "Int", WinActive("A"), "Int", 0)))){
		Suspend, On
		Pause, On
	} else {
		Suspend, Off
		Pause, Off
	}
return
Edit: this will not work since it wont start again.
Please excuse my spelling I am dyslexic.
User avatar
Capn Odin
Posts: 1352
Joined: 23 Feb 2016, 19:45
Location: Denmark
Contact:

Re: if current keyboard layout is english then

26 Jun 2016, 13:21

Found a solution, run this script separately, it will suspend and pause another script depending on the file name in the string Script.ahk - AutoHotkey.

Code: Select all

#Persistent

DetectHiddenWindows, on
SetTitleMatchMode, 2

bool := 1
English := 0x4090409

SetTimer, CheckLang, 200

CheckLang:
	Suspend, Permit
	if(English = Format("0x{:x}", DllCall("GetKeyboardLayout", "Int", DllCall("GetWindowThreadProcessId", "Int", WinActive("A"), "Int", 0)))){
		if(bool){
			PostMessage, 0x111, 65305, , , Script.ahk - AutoHotkey
			PostMessage, 0x111, 65306, , , Script.ahk - AutoHotkey
			bool := False
		}
	} else {
		if(!bool){
			PostMessage, 0x111, 65305, , , Script.ahk - AutoHotkey
			PostMessage, 0x111, 65306, , , Script.ahk - AutoHotkey
			bool := True
		}
	}
return
If you keep your hotkeys in Script.ahk it should work.
Please excuse my spelling I am dyslexic.
Eguy

Re: if current keyboard layout is english then

26 Jun 2016, 13:42

I will try it.Though I like to have 1 script.I ask for this script because English cause problems to my code.thats why I want to turn off my script if current keyboard layout is English.So I think only 1 method could solve the problem the one you gave me with different script and maybe (I think)if I could use reload command.for example if I change to English reload script.if I change again and go to another keyboard layout reload again.So when ever I change layout keyboard reload script.i tried that but I got loop for ever which means script was reloading for ever and it crashed my windows...Can this be done ?

Return to “Ask for Help (v1)”

Who is online

Users browsing this forum: coder96, Joey5 and 355 guests