[CLASS] Lyt - Keyboard layout (language) operation

Post your working scripts, libraries and tools
stealzy
Posts: 73
Joined: 01 Nov 2015, 13:43

[CLASS] Lyt - Keyboard layout (language) operation

17 Feb 2017, 13:24

Class and example usage:

Code: [Select all] [Expand] [Download] GeSHi © Codebox Plus


Bug: do not work in taskbar. Fixed.
Update: layout detect fully work with console windows.
Update: Drugwash fix bug with hardcode max number of layouts.
Last edited by stealzy on 06 Feb 2018, 06:21, edited 13 times in total.
Helgef
Posts: 2990
Joined: 17 Jul 2016, 01:02
Contact:

Re: [CLASS] Lyt - Keyboard layout (language) operation

04 Mar 2017, 04:58

This is excellent! It seems to be very well made :bravo:
From time to time windows decides to change my language settings in some (seemingly random) windows, this is very useful for me.
Thank you!
rommmcek
Posts: 349
Joined: 15 Aug 2014, 15:18

Re: [CLASS] Lyt - Keyboard layout (language) operation

05 Mar 2017, 02:23

@Helgef: Consider this setting! (pic. form Win10)
Attachments
Advanced Language Settings.png
Advanced Language Settings.png (98.92 KiB) Viewed 2743 times
Helgef
Posts: 2990
Joined: 17 Jul 2016, 01:02
Contact:

Re: [CLASS] Lyt - Keyboard layout (language) operation

05 Mar 2017, 03:02

Thank you rommmcek, I couldn't find the corresponding setting on win7, I'll take a closer look late.
lexikos
Posts: 5938
Joined: 30 Sep 2013, 04:07
GitHub: Lexikos

Re: [CLASS] Lyt - Keyboard layout (language) operation

05 Mar 2017, 04:38

stealzy wrote:Remark: layout does not change on taskbar if taskbar on focus.
MS do it by design, so you can click on "Languge bar" in taskbar and layout not switching to taskbar current layout.
Obviously, you do not need change layout on taskbar, because there are no fields to print something ;-).

Right click the taskbar, select Toolbars, then Address. Now there is a field to print something...

It appears that if the taskbar has the focus, the language selector on the taskbar does in fact change the taskbar's current layout, even if there are no "fields to print something".

Clicking on the language selector on the taskbar does not focus the taskbar.
stealzy
Posts: 73
Joined: 01 Nov 2015, 13:43

Re: [CLASS] Lyt - Keyboard layout (language) operation

16 Mar 2017, 14:31

My mistake, if the taskbar has the focus layout still change, but two-letter inscription on language selector not change until taskbar loose focus.
Workaround is only for immediate display of new layout in language selector.
lexikos
Posts: 5938
Joined: 30 Sep 2013, 04:07
GitHub: Lexikos

Re: [CLASS] Lyt - Keyboard layout (language) operation

16 Mar 2017, 20:45

... but two-letter inscription on language selector not change until taskbar loose focus.
The "two-letter inscription" changes immediately if I use the built-in selector or keyboard shortcut on Windows 7 or 10. The taskbar appears to work the same as every other window in this respect.

I just tested your script on Windows 7 and it did not work with the taskbar at all. The language did not change.

I didn't test your script on Windows 10 - my initial point was merely that your explanation was incorrect. Whether your script fails because of a "by design" feature or some kind of bug, I don't know.
stealzy
Posts: 73
Joined: 01 Nov 2015, 13:43

Re: [CLASS] Lyt - Keyboard layout (language) operation

17 Mar 2017, 00:14

I also tested on Windows 7, probably it work precariously.
I remove workaround, let it be bug, I do not know how reliably change layout on focused taskbar, using Sent/PostMessage.
formicant
Posts: 8
Joined: 21 Jan 2018, 21:06

Re: [CLASS] Lyt - Keyboard layout (language) operation

30 Jan 2018, 13:03

Great! Thanks.
(Please note that the method names in the examples differ from the ones in the class. E.g. GetLng ~ GetLocaleName.)

BTW, what is the best way to monitor the layout changing?
burque505
Posts: 437
Joined: 22 Jan 2017, 19:37

Re: [CLASS] Lyt - Keyboard layout (language) operation

30 Jan 2018, 19:16

Hi stealzy, thanks, I like it.
I changed the example above as shown (or hidden) :) below so it would work (thanks formicant!).

Spoiler


Lyt.PNG
Lyt.PNG (21.69 KiB) Viewed 867 times
User avatar
Drugwash
Posts: 560
Joined: 29 May 2014, 21:07
Location: Ploieşti, Romania

Re: [CLASS] Lyt - Keyboard layout (language) operation

31 Jan 2018, 04:27

The info about console language is useful, thank you.

There is a gotcha in the code though: the script assumes the default system shell is Explorer, which may not always be the case (there were/are replacements such as BlackBox/BBLean etc). In such case it may be better to use GetShellWindow(), GetProgmanWindow(), maybe even GetDesktopWindow() - all in user32.dll.

I see each KLID is being retrieved by temporarily activating the respective layout, which even if very brief may interfere with user's typing or automation. The alternative would be to parse the Preload and Substitutes lists in registry, matching against the HKLs (and there's a trick there too) to get to the real KLIDs.

@burque505: There's a slight mistake in your code too: it should be LayoutName, not DisplayName. That will show the layout name after the language name. ;)

[EDIT] Oh shoot, just noticed one language/layout is completely missing from the list, the Swedish one:
LangLayoutList.png
(26.46 KiB) Not downloaded yet


[EDIT2] …and I know why: because you assumed five would be more than enough installed layouts, so you hardcoded that value instead of getting the real one. ;) Here's the correct function:

Code: [Select all] [Expand] [Download] GeSHi © Codebox Plus

I've deleted my CloudMe account because of GDPR - the now legal base for privacy invasion and data theft.
burque505
Posts: 437
Joined: 22 Jan 2017, 19:37

Re: [CLASS] Lyt - Keyboard layout (language) operation

31 Jan 2018, 11:31

Thanks, @Drugwash! Here's how it looks on my system after your fixes:

LytDW.PNG
LytDW.PNG (21.46 KiB) Viewed 818 times
User avatar
Drugwash
Posts: 560
Joined: 29 May 2014, 21:07
Location: Ploieşti, Romania

Re: [CLASS] Lyt - Keyboard layout (language) operation

31 Jan 2018, 11:54

Yep, that is the correct output. :)

Now, since you use an x64 system (I see the long HKLs), could you please test the script below and see if it yields the same results (or better)? I don't have any x64 machines in the house.

Found a couple bugs, fixed below, and also cleaned up a bit. Edited twice since first posted. Please redownload, should work fine now in x64.

Code: [Select all] [Expand] [Download] GeSHi © Codebox Plus

Last edited by Drugwash on 01 Feb 2018, 08:52, edited 1 time in total.
I've deleted my CloudMe account because of GDPR - the now legal base for privacy invasion and data theft.
burque505
Posts: 437
Joined: 22 Jan 2017, 19:37

Re: [CLASS] Lyt - Keyboard layout (language) operation

31 Jan 2018, 18:45

Here's what showed up for the same 7 keyboards as above.
(Having trouble getting the forum to display images at the moment ...)

LytDW2.png
(40.93 KiB) Not downloaded yet
User avatar
Drugwash
Posts: 560
Joined: 29 May 2014, 21:07
Location: Ploieşti, Romania

Re: [CLASS] Lyt - Keyboard layout (language) operation

01 Feb 2018, 03:14

Dang, I desperately need an x64 machine for testing! :(
Thank you, burque. It seems to have trouble with those long negative pointers. Could you please try what's suggested above in the striked out text, that is replacing 2*A_PtrSize with 8?
But first, are you sure you redownloaded the code above? I modified it a bit after initial posting, maybe you got the old version.

Regarding images, my understanding is that images over a certain width are being attached as files rather than being rendered inline, to avoid board misalignment.

[EDIT] Code above was modified twice, should work correctly in x64 now without any modification whatsoever.
Last edited by Drugwash on 01 Feb 2018, 09:46, edited 1 time in total.
I've deleted my CloudMe account because of GDPR - the now legal base for privacy invasion and data theft.
burque505
Posts: 437
Joined: 22 Jan 2017, 19:37

Re: [CLASS] Lyt - Keyboard layout (language) operation

01 Feb 2018, 09:06

Here's some results with 2*A_PtrSize, 8, and then 16.
LytDW2.png
LytDW2.png (27.43 KiB) Viewed 745 times

LytDW_8.png
LytDW_8.png (25.74 KiB) Viewed 745 times

LytDW_16.png
LytDW_16.png (23.6 KiB) Viewed 745 times
User avatar
Drugwash
Posts: 560
Joined: 29 May 2014, 21:07
Location: Ploieşti, Romania

Re: [CLASS] Lyt - Keyboard layout (language) operation

01 Feb 2018, 10:01

Latest version should work fine without any modification. We should stop here until I polish it a little and start a new topic, then a moderator will hopefully move relevant posts there to remove this hijacking.
I've deleted my CloudMe account because of GDPR - the now legal base for privacy invasion and data theft.
stealzy
Posts: 73
Joined: 01 Nov 2015, 13:43

Re: [CLASS] Lyt - Keyboard layout (language) operation

06 Feb 2018, 05:35

Hi all!
@formicant, you're right, thanks, fix all my codeboxes :facepalm:.
I think you need hook on window message to monitor the layout changing. Also, hook on window activate and creating, such every window has it's own layout.

@Drugwash, thanks for fix my hardcode :thumbup:! Update top post just now, btw feel free to modify it, i go to the forum at least once a week.
GetKLIDfromHKL() works such because WinAPI GetKeyboardLayoutName works this way. I don't like it, but it work fast (I checked it with A_TickCount) and right way.
I test it on my x64 OS with both AutoHotkeyA32.exe and AutoHotkeyU64.exe.
Drugwash wrote:It seems to have trouble with those long negative pointers

Pointer is not negative, just 8-bytes against 4, but there is nothing to worry unless you convert it to decimal view wrong way.
GetKeyboardLayout() always return full size HKL for your system, but in PostMessage you must use 4-byte HKL if AutoHotkey process is 32-byte.
Dvorak on OSx64 0xfffffffff0020409 -> 0xf0020409 Dvorak on OSx86. It's already works fine with pointers, so don't worry ;).

@Drugwash, look throw your code, DllCall("GetUserDefaultLangID") != system default layout :HeHe:.
It is system locale (time format, etc). Try change default layout in lang bar if you want proof.
Actually system default layout KLID written in registry: HKCU\Keyboard Layout\Preload\1.
Don't know why Hex2Str() look this way, maybe you find usefull this function:

Code: [Select all] [Download] GeSHi © Codebox Plus

hex(n) {
Return Format("{:#0" 2 + 2*A_PtrSize "x}", n)
}
User avatar
Drugwash
Posts: 560
Joined: 29 May 2014, 21:07
Location: Ploieşti, Romania

Re: [CLASS] Lyt - Keyboard layout (language) operation

06 Feb 2018, 11:01

Yeah, I managed to fix a few things since posting that code above, the offline version now correctly detects Default User Layout and System User Layout, but it wasn't easy to find out the proper way. At least I think it's the proper way, but it's possible a a user with limited rights may not be able to retrieve System Default Layout. Dunno, haven't checked - I always give admin rights to users on my machines. Someday I'll post the code in a new topic, maybe someone will offer feedback.

HKLs seem to be 8 bytes even on XP, I found that out during tests. Actually, truncating them to 4 bytes will yield the wrong result when they're in the form of 0xFFFFffffXXXXYYYY.

Hex2Str() is just for prettifying the display but it erroneously interfered with the HKLs in GetHKL(). It allows for some fine customization of the output. The Format() function is so weird I can never understand it, besides I prefer basic syntax as one day I may go back to my 98SE machine after I fix it and don't wanna get bad habits in the mean time. :)
I've deleted my CloudMe account because of GDPR - the now legal base for privacy invasion and data theft.

Return to “Scripts and Functions”

Who is online

Users browsing this forum: No registered users and 15 guests