[CLASS] Lyt - Keyboard layout (language) operation

Post your working scripts, libraries and tools for AHK v1.1 and older
antoniy
Posts: 3
Joined: 29 Apr 2018, 06:51

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

Post by antoniy » 29 Apr 2018, 07:02

Hi,

The script/class lyt from stealzy otherwise perfectly working, fails to switch keyboard layout if just a desktop is selected. Use-case: I want to rename the file located on the desktop, press the trigger button (CaseLock in my case), but nothing happens. AHK correctly sends the event to the script (checked with the msgbox), but the layout stays in the old position. If I do file rename in Explorer window, I can switch layout normally.

I think the problem happening because there is actually "no process" to switch the layout. The problem lies somewhere in the mechanism of Lyt class, how it selects the processes to switch the layout. In this case I think the explorer.exe must be manipulated, although its process window is not active.

Could anybody check my assumptions and fix idea please? I will be glad to try the fix and write back if it worked.

That's the script I use:

Code: Select all

toggle=1
Capslock::
    if (toggle:=!toggle)
        Lyt.Set(0x4070409)
    else
        Lyt.Set("RU")
    SoundBeep 999,1
Return
Kind regards,
Anton

User avatar
Drugwash
Posts: 850
Joined: 29 May 2014, 21:07
Location: Ploieşti, Romania
Contact:

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

Post by Drugwash » 29 Apr 2018, 08:20

Just for a short test, please try to add this code in the Set() function right before IfEqual hWnd, 0, Return "Window not found" and try again:

Code: Select all

hDesk := DllCall("user32\GetDesktopWindow", "Ptr")
If (hWnd != hDesk)
  msgbox, hwnd mismatch!
If you get the 'hwnd mismatch' message then that may be the problem.
Next, try to bypass the hWnd detection and use directly the handle retrieved by GetDesktopWindow(). If it works that way then you'll know for sure where the problem lies. I'm not sure how to fix this however.
Part of my AHK work can be found here.

antoniy
Posts: 3
Joined: 29 Apr 2018, 06:51

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

Post by antoniy » 29 Apr 2018, 10:01

Hi @Drugwash,

Thank you for your prompt reply!

I inserted the code, however it fires a message box in any cases - whether it is a desktop or an application window.
The beginning of the Set() function looks now like:

Code: Select all

        Set(arg := "switch", win := "") {
                hDesk := DllCall("user32\GetDesktopWindow", "Ptr")
                If (hWnd != hDesk)
                    msgbox, hwnd mismatch!

                IfEqual win, 0, Return "Window not found"
Kind regards,
Anton Golubev

stealzy
Posts: 91
Joined: 01 Nov 2015, 13:43

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

Post by stealzy » 29 Apr 2018, 10:03

On my OS (Win7x64) Lyt code can switch layout while I renaming the file located on the desktop :think:.
In my case WinExist("A") return ID of window with class "WorkerW", so it take a message.

User avatar
Drugwash
Posts: 850
Joined: 29 May 2014, 21:07
Location: Ploieşti, Romania
Contact:

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

Post by Drugwash » 29 Apr 2018, 11:56

antoniy wrote:Hi @Drugwash,

Thank you for your prompt reply!

I inserted the code, however it fires a message box in any cases - whether it is a desktop or an application window.
The beginning of the Set() function looks now like:

Code: Select all

        Set(arg := "switch", win := "") {
                hDesk := DllCall("user32\GetDesktopWindow", "Ptr")
                If (hWnd != hDesk)
                    msgbox, hwnd mismatch!

                IfEqual win, 0, Return "Window not found"
Kind regards,
Anton Golubev
That's not correct, Anton, the Set() function should have been:

Code: Select all

Set(arg := "switch", win := "") {
		IfEqual win, 0, Return "Window not found"
		hWnd := (win = "")
						? WinExist("A")
						: ( win + 0
								? WinExist("ahk_id" win)
								: win = "global"
									? win
									: WinExist(win) )
  hDesk := DllCall("user32\GetDesktopWindow", "Ptr")
  If (hWnd != hDesk)
      msgbox, hwnd mismatch!
		IfEqual hWnd, 0, Return "Window not found" ; WinExist() return 0
However, since according to stealzy's reply there is another window that should take the message, the whole issue may lie in a missing directive: DetectHiddenWindows, On. Please add that directive to the autoexec section of your script and see if the code then works.
Part of my AHK work can be found here.

stealzy
Posts: 91
Joined: 01 Nov 2015, 13:43

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

Post by stealzy » 29 Apr 2018, 15:38

Drugwash wrote:add that directive
I don't think this is enough, because it will not have an effect on WinExist("A") id return.
Btw, I try send PostMessage, 0x50 message directly to window with id hDesk := DllCall("user32\GetDesktopWindow", "Ptr"),
it not change layout while I renaming file on desktop.
Anton, could you please specify your OS version. Have you tried use x64 AutoHotkey interpreter?

antoniy
Posts: 3
Joined: 29 Apr 2018, 06:51

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

Post by antoniy » 30 Apr 2018, 01:37

Morning Drugwash, stealzy!

Nice that you support this discussion! :)

Experiment 1:

This snipped produces "hwn mismatch" message box, when I press CapsLock on the desktop. I also tried to close screen captures and screen drawers to minimize risk of hidden windows -> same effect.

Code: Select all

        Set(arg := "switch", win := "") {
                IfEqual win, 0, Return "Window not found"
                hWnd := (win = "")
                                                ? WinExist("A")
                                                : ( win + 0
                                                                ? WinExist("ahk_id" win)
                                                                : win = "global"
                                                                        ? win
                                                                        : WinExist(win) )
                hDesk := DllCall("user32\GetDesktopWindow", "Ptr")
                If (hWnd != hDesk)
                     msgbox, hwnd mismatch!
                IfEqual hWnd, 0, Return "Window not found" ; WinExist() return 0
AHK version v1.1.28.02 - April 7, 2018
Script is executed with AutoHotkeyU64.exe process.
Windows 10 version 1709 (05 Build 16299.371)

AHK Windows Spy reports:
Program Manager
ahk_class Progman
ahk_exe Explorer.EXE


Experiment 2:
Set

Code: Select all

DetectHiddenWindows, On
just before loading the Lyt class. No change of keyboard layout on the desktop.

Experiment 3:
On Windows 7, x64, same script - does not work either!

Experiment 4 (to check interference with other code):
Closed all AHK processes. Extracted just Lyt code with CapsLock hook and started it -> does not work on the desktop.

Thank you!
Anton

popobawa
Posts: 2
Joined: 18 Jan 2018, 10:24

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

Post by popobawa » 20 Aug 2018, 22:28

It does not work on Run windows (win+r) on windows 10
:(

formicant
Posts: 9
Joined: 21 Jan 2018, 21:06

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

Post by formicant » 13 Sep 2019, 02:14

The GetInputHKL method does not work on x64 because of this line:

Code: Select all

Return HKL & ((1 << 8*A_PtrSize) - 1)
The behaviour of 1 << 64 is undefined. It does not always return 0 as one could expect.


This will work:

Code: Select all

Return A_PtrSize = 4 ? HKL & 0xFFFFFFFF : HKL

JanSal
Posts: 21
Joined: 19 Aug 2016, 02:19

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

Post by JanSal » 04 Oct 2022, 06:43

Thank you for sharing this library!
It mostly works, but crashes my Anki installation (v2.1.54, Qt6 or Qt5).
What route would you go down to debug this issue?
I am grateful for any suggestions.

Post Reply

Return to “Scripts and Functions (v1)”