 |
AutoHotkey Community Let's help each other out
|
| View previous topic :: View next topic |
| Author |
Message |
Guest1122 Guest
|
Posted: Thu Jun 11, 2009 2:00 pm Post subject: How to get the window id/title/whatever at a specific xy |
|
|
How do I get a window id/title/whatever at a specific position? Then activate it, without moving the mouse?
example:
x = 320
y = 500
??, x, y, wndw
WinActivate, ahk_id %wndw%
Thanks..... |
|
| Back to top |
|
 |
SKAN
Joined: 26 Dec 2005 Posts: 8688
|
Posted: Thu Jun 11, 2009 2:09 pm Post subject: |
|
|
| Code: | | WinActivate, % "ahk_id" DllCall("WindowFromPoint", Int,320, Int,500 ) |
|
|
| Back to top |
|
 |
Learning one
Joined: 04 Apr 2009 Posts: 1000 Location: Croatia
|
Posted: Fri Mar 19, 2010 11:03 pm Post subject: |
|
|
I tried to write a function based on SKAN's code that gets info about window at given coordinates
But this works more like GetControlAtCoords, not as GetWinAtCoords...
What's wrong?
| Code: | GetWinAtCoords(x,y,what="ID") ; works like GetControlAtCoords?
{
WinID := DllCall("WindowFromPoint", Int,x, Int,y) ; by SKAN --> is it WinID or ControlID?
if what = ID
Return WinID
else if what = Class
{
WinGetClass, WinClass, ahk_id %WinID%
Return WinClass
}
else if what = Title
{
WinGetTitle, WinTitle, ahk_id %WinID%
Return WinTitle
}
else if what = PID
{
WinGet, WinPID, PID, ahk_id %WinID%
Return WinPID
}
}
;===Test===
1::
x := 100, y := 100
MsgBox, % GetWinAtCoords(x,y,"ID") "`n" GetWinAtCoords(x,y,"Class") "`n" GetWinAtCoords(x,y,"Title") "`n" GetWinAtCoords(x,y,"PID")
Return |
WindowFromPoint Function ()
| WindowFromPoint Function () wrote: | | If the point is over a static text control, the return value is a handle to the window under the static text control. | So in this case window's (not control's) handle would be returned as well? Am I right? |
|
| Back to top |
|
 |
SKAN
Joined: 26 Dec 2005 Posts: 8688
|
Posted: Sat Mar 20, 2010 3:34 pm Post subject: |
|
|
| Learning one wrote: | | is it WinID or ControlID? |
Seems to be Control's hWnd
Try replacing
| Code: | | WinID := DllCall("WindowFromPoint", Int,x, Int,y) | with | Code: | WinID := DllCall( "GetAncestor", UInt
,DllCall( "WindowFromPoint", Int,X, Int,Y )
, UInt,GA_ROOTOWNER := 3 ) |
|
|
| Back to top |
|
 |
Learning one
Joined: 04 Apr 2009 Posts: 1000 Location: Croatia
|
Posted: Sat Mar 20, 2010 5:55 pm Post subject: |
|
|
That's it! Thank you! So here it is:
| Code: | GetWinAtCoords(x,y,what="Title") ; by SKAN and Learning one
{
; Returns Title/ID/Class/PID of window at given coordinates
WinID := DllCall( "GetAncestor", UInt ; by SKAN
,DllCall( "WindowFromPoint", Int,X, Int,Y )
, UInt, GA_ROOT := 2)
if what = Title
{
WinGetTitle, WinTitle, ahk_id %WinID%
Return WinTitle
}
else if what = ID
Return WinID
else if what = Class
{
WinGetClass, WinClass, ahk_id %WinID%
Return WinClass
}
else if what = PID
{
WinGet, WinPID, PID, ahk_id %WinID%
Return WinPID
}
} |
Last edited by Learning one on Sat Mar 20, 2010 9:48 pm; edited 2 times in total |
|
| Back to top |
|
 |
SKAN
Joined: 26 Dec 2005 Posts: 8688
|
Posted: Sat Mar 20, 2010 7:49 pm Post subject: |
|
|
Oops! One alteration required:
| Code: | WinID := DllCall( "GetAncestor", UInt
,DllCall( "WindowFromPoint", Int,X, Int,Y )
, UInt,GA_ROOT := 2 ) |
GA_ROOTOWNER returns Taskbar for Startmenu in WinXP!
GA_ROOT works in expected manner. |
|
| Back to top |
|
 |
Learning one
Joined: 04 Apr 2009 Posts: 1000 Location: Croatia
|
Posted: Sat Mar 20, 2010 9:46 pm Post subject: |
|
|
| Altered. |
|
| Back to top |
|
 |
Guest
|
Posted: Sun Mar 28, 2010 4:26 am Post subject: |
|
|
Thanks for this info...
Only one thing is left to solve: how to determine the control Class NN at specific coordinates. |
|
| Back to top |
|
 |
SKAN
Joined: 26 Dec 2005 Posts: 8688
|
Posted: Sun Mar 28, 2010 8:48 am Post subject: |
|
|
| Anonymous wrote: | | how to determine the control Class NN at specific coordinates. |
| Code: | ; Ascertaining Control's hWnd/ClassNN for given coordinates ; By SKAN | 28-March-2010
; Forum Topic : www.autohotkey.com/forum/viewtopic.php?t=45186
If ! WinExist( "Calculator ahk_class SciCalc" ) {
Run Calc
WinWait, Calculator ahk_class SciCalc
}
hWnd := WinExist( "Calculator ahk_class SciCalc" )
hCtrl := Control_ByPos( hWnd,10,10 )
ClassNN := Control_GetClassNN( hWnd,hCtrl )
MsgBox, 0, Control @10`,10, %ClassNN%
Return ; // End of auto-execute section //
Control_ByPos( hPar, x=0, y=0 ) { ; www.autohotkey.com/forum/viewtopic.php?p=343110#343110
hWnd := ( ID := WinExist( "ahk_id" hPar) ) ? ID : WinExist( hPar )
Return WinExist( "ahk_id" DllCall( "ChildWindowFromPoint", UInt,hWnd, Int,x, Int,y ) )
}
Control_GetClassNN( hPar,hCtrl ){ ; www.autohotkey.com/forum/viewtopic.php?p=301151#301151
hWnd := ( ID := WinExist( "ahk_id" hPar) ) ? ID : WinExist( hPar )
WinGet, CH, ControlListHwnd, ahk_id %hWnd%
WinGet, CN, ControlList, ahk_id %hWnd%
LF:= "`n", CH:= LF CH LF, CN:= LF CN LF, S:= SubStr( CH, 1, InStr( CH, LF hCtrl LF ) )
StringReplace, S, S,`n,`n, UseErrorLevel
StringGetPos, P, CN, `n, L%ErrorLevel%
Return SubStr( CN, P+2, InStr( CN, LF, 0, P+2 ) -P-2 )
} |
|
|
| Back to top |
|
 |
|
|
You can post new topics in this forum You can reply to topics in this forum
|
Powered by phpBB © 2001, 2005 phpBB Group
|