OnMessage(WM_MouseMove) to work only if gui window is active?
OnMessage(WM_MouseMove) to work only if gui window is active?
Hello all
I'm using this example on my gui script: https://www.autohotkey.com/docs/commands/Gui.htm#ExToolTip
My problem is the OnMessage function is being executed on every mouse movement, even if the gui window is not active, minimized or even destroyed. Yes I know this is how is supposed to work, and that I can disable that on message with "" parameter on it.
But I'm trying to make it work only when the gui window is active, and not execute it on everymouse move. I tried with If WinActive("ahk class AutoHotkeyGUI") inside the onmessage function and the tooltip is not showing if the window is not active but still it checks if the window is active or not on every mouse movement. I'd rather a better and clean solution for this.
This is driving me mad and cannot find anything about it.
How can I accomplish this?
Thank you all for your time reading my post
Regards
I'm using this example on my gui script: https://www.autohotkey.com/docs/commands/Gui.htm#ExToolTip
My problem is the OnMessage function is being executed on every mouse movement, even if the gui window is not active, minimized or even destroyed. Yes I know this is how is supposed to work, and that I can disable that on message with "" parameter on it.
But I'm trying to make it work only when the gui window is active, and not execute it on everymouse move. I tried with If WinActive("ahk class AutoHotkeyGUI") inside the onmessage function and the tooltip is not showing if the window is not active but still it checks if the window is active or not on every mouse movement. I'd rather a better and clean solution for this.
This is driving me mad and cannot find anything about it.
How can I accomplish this?
Thank you all for your time reading my post
Regards
Re: OnMessage(WM_MouseMove) to work only if gui window is active?
You can unregister the function following WinWaitNotActive.
Re: OnMessage(WM_MouseMove) to work only if gui window is active?
it will be the same as I said with if winactive {
I need to work it when the window is active, and idle when is minimized or non existent.
Re: OnMessage(WM_MouseMove) to work only if gui window is active?
What are you trying to achieve? Do you have an example of a script that is not achieving that?
Re: OnMessage(WM_MouseMove) to work only if gui window is active?
No, it would not be the same. It would not be constantly going to your function or constantly doing anything else either. You could use both WinWaitActive and WinWaitNotActive inside a loop, and when it reaches each of them, it would enable or disable the OnMessage respectively, then it wouldn't be going to your function triggered by OnMessage when it's not active, which is what you said you wanted. And if you're concerned about it constantly looping, it wouldn't be doing that. It would just stop and wait on either command that waits for the window to be active or not. And if your script is GUI event driven, then you can let that loop do its thing and the script will still respond to button presses or whatever, as is demonstrated in the script below. It beeps whenever the WM_MOUSEMOVE() function is called, and as you'll see, it is not called at any time when some other program's window is active even if you move the mouse over the GUI.
Code: Select all
Gui, +HwndGuiID
Gui, Add, Button, y30 w150 gButtonClicked, My button
Gui, Show, h80
OnMessage(0x0200, "WM_MOUSEMOVE")
loop {
WinWaitNotActive, ahk_id %GuiID%
OnMessage(0x0200, "WM_MOUSEMOVE", 0)
WinWaitActive, ahk_id %GuiID%
OnMessage(0x0200, "WM_MOUSEMOVE", 1)
}
return
ButtonClicked:
MsgBox, Button was clicked
return
WM_MOUSEMOVE() {
SoundBeep
}
GuiClose:
ExitApp
Re: OnMessage(WM_MouseMove) to work only if gui window is active?
Thank you both!
as the boiler post, that is best solution for what I want, inside the loop the winwait will be waiting for that window and not executing any function call to check if the window is active or not and it will not cause an useless cpu usage which that was the main reason.
as the boiler post, that is best solution for what I want, inside the loop the winwait will be waiting for that window and not executing any function call to check if the window is active or not and it will not cause an useless cpu usage which that was the main reason.
-
- Posts: 4330
- Joined: 29 Mar 2015, 09:41
- Contact:
Re: OnMessage(WM_MouseMove) to work only if gui window is active?
Without a cycle:
Code: Select all
OnMessage(0x6, "WM_ACTIVATE")
Gui, Show, w300 h300
WM_ACTIVATE(wp, lp) {
OnMessage(0x200, wp ? "WM_MOUSEMOVE" : "")
}
WM_MOUSEMOVE(wp, lp) {
ToolTip WM_MOUSEMOVE
}
Re: OnMessage(WM_MouseMove) to work only if gui window is active?
That's definitely the way to go. I tried that, and I got some weird thing happening where the title bar of the GUI would not be shaded correctly to indicate when it was active or not (even when I activated another window, both title bars would show that they were the active window). I must have done something else to cause that, but I can't see what.
-
- Posts: 4330
- Joined: 29 Mar 2015, 09:41
- Contact:
Re: OnMessage(WM_MouseMove) to work only if gui window is active?
I haven't encountered such an effect yet.
Re: OnMessage(WM_MouseMove) to work only if gui window is active?
I don't see it when I run yours. Mine must have done something different, although I used 0x6 WM_ACTIVATE and there weren't that many moving parts. Instead of a ternary operator, I used an if statement, but it otherwise seems like it would be the same. Not important anyway. Just wondering what I may have done to cause that.
Re: OnMessage(WM_MouseMove) to work only if gui window is active?
I’m not understanding the wp and lp variables, what are they for? And how is wp will be true of I want it only on the gui window?teadrinker wrote: ↑08 May 2021, 06:18Without a cycle:Code: Select all
OnMessage(0x6, "WM_ACTIVATE") Gui, Show, w300 h300 WM_ACTIVATE(wp, lp) { OnMessage(0x200, wp ? "WM_MOUSEMOVE" : "") } WM_MOUSEMOVE(wp, lp) { ToolTip WM_MOUSEMOVE }
-
- Posts: 4330
- Joined: 29 Mar 2015, 09:41
- Contact:
Re: OnMessage(WM_MouseMove) to work only if gui window is active?
Yeah, mine was something like:
..which could also be:
When I plug that into your code, I don't see the problem. Strange. Maybe I had a typo or something. I didn't save it as I did it in CodeQuickTester.
Code: Select all
WM_ACTIVATE(wparam) {
if wparam
OnMessage(0x200, "WM_MOUSEMOVE", 1)
else
OnMessage(0x200, "WM_MOUSEMOVE", 0)
}
Code: Select all
WM_ACTIVATE(wparam) {
OnMessage(0x200, "WM_MOUSEMOVE", !!wparam)
}
Re: OnMessage(WM_MouseMove) to work only if gui window is active?
That's a cool script!
-
- Posts: 4330
- Joined: 29 Mar 2015, 09:41
- Contact:
-
- Posts: 4330
- Joined: 29 Mar 2015, 09:41
- Contact:
Re: OnMessage(WM_MouseMove) to work only if gui window is active?
Thanks. Doesn’t seem to cause a problem, though.