[CLASS] Lyt - Keyboard layout (language) operation

Post your working scripts, libraries and tools
antoniy
Posts: 3
Joined: 29 Apr 2018, 06:51

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

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: 642
Joined: 29 May 2014, 21:07
Location: Ploieşti, Romania

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

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.
I've deleted my CloudMe account because of GDPR - the now legal base for privacy invasion and data theft.
antoniy
Posts: 3
Joined: 29 Apr 2018, 06:51

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

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: 82
Joined: 01 Nov 2015, 13:43

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

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: 642
Joined: 29 May 2014, 21:07
Location: Ploieşti, Romania

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

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.
I've deleted my CloudMe account because of GDPR - the now legal base for privacy invasion and data theft.
stealzy
Posts: 82
Joined: 01 Nov 2015, 13:43

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

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

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

20 Aug 2018, 22:28

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

Return to “Scripts and Functions”

Who is online

Users browsing this forum: No registered users and 48 guests