How to send messages to a modal dialog box? Topic is solved

Get help with using AutoHotkey and its commands and hotkeys
SnakE
Posts: 2
Joined: 20 Nov 2017, 14:02

How to send messages to a modal dialog box?

20 Nov 2017, 14:12

Hello,
I'm using the following AHK script to switch keyboard layouts with Caps Lock in Windows 10:

Code: [Select all] [Download] (Untitled.ahk)GeSHi © Codebox Plus

WM_INPUTLANGCHANGEREQUEST := 0x50
INPUTLANGCHANGE_FORWARD := 0x0002
HKL_NEXT := 1
Capslock::
PostMessage, WM_INPUTLANGCHANGEREQUEST, INPUTLANGCHANGE_FORWARD, HKL_NEXT, , A
Return

It works well for normal windows. However if any modal dialog box is on the screen, like Save As, or a search dialog in Notepad++, the layout switch stops working. I assume this is because the "A" window selector does not select the dialog but the main app window and the message gets ignored. Is there any way to fix this?
Georgie Munteer

Re: How to send messages to a modal dialog box?

20 Nov 2017, 15:21

SnakE wrote:Hello,
I'm using the following AHK script to switch keyboard layouts with Caps Lock in Windows 10:

Code: [Select all] [Download] (Untitled.ahk)GeSHi © Codebox Plus

WM_INPUTLANGCHANGEREQUEST := 0x50
INPUTLANGCHANGE_FORWARD := 0x0002
HKL_NEXT := 1
Capslock::
PostMessage, WM_INPUTLANGCHANGEREQUEST, INPUTLANGCHANGE_FORWARD, HKL_NEXT, , A
Return

It works well for normal windows. However if any modal dialog box is on the screen, like Save As, or a search dialog in Notepad++, the layout switch stops working. I assume this is because the "A" window selector does not select the dialog but the main app window and the message gets ignored. Is there any way to fix this?


you can use exclude title and give the title of the windows you want to ignore https://autohotkey.com/docs/commands/PostMessage.htm
teadrinker
Posts: 303
Joined: 29 Mar 2015, 09:41

Re: How to send messages to a modal dialog box?  Topic is solved

20 Nov 2017, 16:12

For me this works:

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

Capslock::
ControlGetFocus, CtrlFocus, A
PostMessage, WM_INPUTLANGCHANGEREQUEST := 0x50, INPUTLANGCHANGE_FORWARD := 0x2,, %CtrlFocus%, A
Return
SnakE
Posts: 2
Joined: 20 Nov 2017, 14:02

Re: How to send messages to a modal dialog box?

20 Nov 2017, 19:26

George, I don't think I want to ignore windows. On the contrary I want to send messages to the topmost popup even if it's not the main window.

teadrinker, thank you! This works perfectly. Exactly what I wanted.

On a side note: the script I posted originally was exactly what was working for me most of the time. Note that I passed variables to a command without wrapping them in percent signs. How did that work? Documentation sounds like it shouldn't have. Does PostMessage support symbolic message names? My current script is like this, and it works well:

Code: [Select all] [Download] (Untitled.ahk)GeSHi © Codebox Plus

WM_INPUTLANGCHANGEREQUEST := 0x50
INPUTLANGCHANGE_FORWARD := 0x0002
HKL_NEXT := 1
Capslock::
ControlGetFocus, CtrlFocus, A
PostMessage, %WM_INPUTLANGCHANGEREQUEST%, %INPUTLANGCHANGE_FORWARD%, %HKL_NEXT%, %CtrlFocus%, A
Return
teadrinker
Posts: 303
Joined: 29 Mar 2015, 09:41

Re: How to send messages to a modal dialog box?

21 Nov 2017, 04:06

SnakE wrote:How did that work?

According the documentation:
Msg

The message number to send, which can be an expression. See the message list to determine the number.
wParam

The first component of the message, which can be an expression. If blank or omitted, 0 will be sent.
lParam

The second component of the message, which can be an expression. If blank or omitted, 0 will be sent.

Variable names in an expression are not enclosed in percent signs

So, this is correct:

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

WM_INPUTLANGCHANGEREQUEST := 0x50
INPUTLANGCHANGE_FORWARD := 0x0002
HKL_NEXT := 1
Capslock::
ControlGetFocus, CtrlFocus, A
PostMessage, WM_INPUTLANGCHANGEREQUEST, INPUTLANGCHANGE_FORWARD, HKL_NEXT, %CtrlFocus%, A
Return

Return to “Ask For Help”

Who is online

Users browsing this forum: holahapi, tijger and 41 guests