I don't get it guys.
When I use the MouseGetPos to obtain the window ID of the active window that the mouse is currently over and then, when I use the WinActive(A), the two IDs are different!!!
It took me so long to figure this out. I hate AutoHotkey! I couldn't figure one part of my script out for such a long time.
Why are they different. Is one a different type of ID than the other? What is the exact difference in names?!
Which one is the real ID and then how do I obtain the ID of the window that my mouse is hovering over?
Can windows have 2 different IDs???!? Getmousepos not equal to WinActive
-
- Posts: 87
- Joined: 06 Sep 2017, 19:29
Re: Can windows have 2 different IDs???!? Getmousepos not equal to WinActive
Are you talking about class, exe, or pid? What does Window Spy tell you about the window in question?
Re: Can windows have 2 different IDs???!? Getmousepos not equal to WinActive
How exactly are you using them? Something Like this?BannerStore wrote: ↑03 Feb 2020, 15:06When I use the MouseGetPos to obtain the window ID of the active window that the mouse is currently over and then, when I use the WinActive(A), the two IDs are different!!!
Code: Select all
Loop
{
MouseGetPos,,, PosWin
Tooltip % PosWin " " WinActive( "A" )
}
Escape::ExitApp
-
- Posts: 87
- Joined: 06 Sep 2017, 19:29
Re: Can windows have 2 different IDs???!? Getmousepos not equal to WinActive
Going through my script carefully, I realized that the ways I get the window IDs are through GetMousePos, WinActive, and WinGet. Below is a quick script I wrote. I'm going to first retrieve the window IDs of 2 windows. This is accomplished within the MouseIsOver function located at the bottom.
First, run the script. Then, hover your mouse over a Chrome page without activating it (Another webpage should be activated). Press F5 to see the values of the ID variables. It should give you the window ID of the active window and the Chrome page. Then activate Chrome and press control F5 and you'll notice the window ID of the active Chrome page changes. The one from getting mouse position is different than the one from getting WinGet. They are always different. Why? Which do you use?
Sometimes, the active window is always 0x0 for the active window no matter which window becomes active. Sometimes, it comes up continually blank. When you get the ID via WinGet and MousePos, the IDs will differ. Which is correct?
First, run the script. Then, hover your mouse over a Chrome page without activating it (Another webpage should be activated). Press F5 to see the values of the ID variables. It should give you the window ID of the active window and the Chrome page. Then activate Chrome and press control F5 and you'll notice the window ID of the active Chrome page changes. The one from getting mouse position is different than the one from getting WinGet. They are always different. Why? Which do you use?
Code: Select all
Global OverWinID, OverTitle, AWindowID, AWindowTitle
#If (MouseIsOver(Chrome_WidgetWin_1")) and (%ActWinTitle%!=%OverTitle%)
{
^F5::
MsgBox Window IDs: OverTitle = %OverTitle%`n`nAWindowTitle = %AWindowTitle%`n`nOverwinID = %OverWinID%`n`nAWindowID = %AWindowID%`n`n
Return
}
#If
MouseIsOver(WinTitle) {
[b]MouseGetPos,,, OverWinID[/b]
[b]AWindowID:=WinActive(A)[/b]
WinGetTitle, AWindowTitle, A
WinGetTitle, OverTitle, ahk_id %OverWinID%
WinGetClass, OverWinClass, ahk_id %OverWinID%
Return WinTitle=OverWinClass
}
Return
TLM wrote: ↑03 Feb 2020, 15:35How exactly are you using them? Something Like this?BannerStore wrote: ↑03 Feb 2020, 15:06When I use the MouseGetPos to obtain the window ID of the active window that the mouse is currently over and then, when I use the WinActive(A), the two IDs are different!!!It's always helpful to post your code.Code: Select all
Loop { MouseGetPos,,, PosWin Tooltip % PosWin " " WinActive( "A" ) } Escape::ExitApp
Re: Can windows have 2 different IDs???!? Getmousepos not equal to WinActive
@BannerStore try this & see my commentsFor future reference, conditions with variables should not be enclosed in percents (ActWinTitle!=OverTitle)
Code: Select all
Global OverWinID, OverTitle, AWindowID, AWindowTitle
; directive #If statements do not need to be enclosed in curly braces { }
#If ( MouseIsOver( "Chrome_WidgetWin_1" ) and !WinActive( "ahk_class Chrome_WidgetWin_1" ) )
^F5::
MsgBox Window IDs: OverTitle = %OverTitle%`n`nAWindowTitle = %AWindowTitle%`n`nOverwinID = %OverWinID%`n`nAWindowID = %AWindowID%`n`n
#If
Return
MouseIsOver( WinTitle )
{
MouseGetPos,,, OverWinID
AWindowID:=WinActive( "A" ) ; strings must be in quotes
WinGetTitle, OverTitle, ahk_id %OverWinID%
WinGetTitle, AWindowTitle, A
WinGetClass, OverWinClass, ahk_id %OverWinID%
Return ( WinTitle = OverWinClass )
}
-
- Posts: 87
- Joined: 06 Sep 2017, 19:29
Re: Can windows have 2 different IDs???!? Getmousepos not equal to WinActive
TLM, Thanks for your help!!
I've been trying to fix other parts of my script so I haven't had time to respond to you so, sorry!
Anyway, I'll try to go over what you suggested and if I can fix what is going on.
I just wanted to let you know and everybody else that I appreciate your help. It helps a lot!
By the way, I put { } and returns everywhere because I still don't have a solid grasp of the syntax of AutoHotkey yet. I keep forgetting which function/commands need which. It's A LOT to memorize! I figure if I put it in, it won't hurt and it might fix somethihng.
I've been trying to fix other parts of my script so I haven't had time to respond to you so, sorry!
Anyway, I'll try to go over what you suggested and if I can fix what is going on.
I just wanted to let you know and everybody else that I appreciate your help. It helps a lot!
By the way, I put { } and returns everywhere because I still don't have a solid grasp of the syntax of AutoHotkey yet. I keep forgetting which function/commands need which. It's A LOT to memorize! I figure if I put it in, it won't hurt and it might fix somethihng.
TLM wrote: ↑03 Feb 2020, 19:07@BannerStore try this & see my commentsFor future reference, conditions with variables should not be enclosed in percents (ActWinTitle!=OverTitle)Code: Select all
Global OverWinID, OverTitle, AWindowID, AWindowTitle ; directive #If statements do not need to be enclosed in curly braces { } #If ( MouseIsOver( "Chrome_WidgetWin_1" ) and !WinActive( "ahk_class Chrome_WidgetWin_1" ) ) ^F5:: MsgBox Window IDs: OverTitle = %OverTitle%`n`nAWindowTitle = %AWindowTitle%`n`nOverwinID = %OverWinID%`n`nAWindowID = %AWindowID%`n`n #If Return MouseIsOver( WinTitle ) { MouseGetPos,,, OverWinID AWindowID:=WinActive( "A" ) ; strings must be in quotes WinGetTitle, OverTitle, ahk_id %OverWinID% WinGetTitle, AWindowTitle, A WinGetClass, OverWinClass, ahk_id %OverWinID% Return ( WinTitle = OverWinClass ) }
Re: Can windows have 2 different IDs???!? Getmousepos not equal to WinActive
No worries, I've been using AHk for years and I still make mistakes.BannerStore wrote: ↑05 Feb 2020, 22:48I keep forgetting which function/commands need which. It's A LOT to memorize!
Code: Select all
#If ( MouseIsOver( "Chrome_WidgetWin_1" ) and !WinActive( "ahk_class Chrome_WidgetWin_1" ) )
^F5::
MsgBox Window IDs: OverTitle = %OverTitle%`n`nAWindowTitle = %AWindowTitle%`n`nOverwinID = %OverWinID%`n`nAWindowID = %AWindowID%`n`n
Return ; move the return here in case you want to add more hotkeys to the above directive.
#If
Who is online
Users browsing this forum: chubbychub, Google [Bot], MrHue and 95 guests