Kubofonista Posted January 2, 2009 Share Posted January 2, 2009 Hi. I'm want to get window / control handle by mouse click / pos. How I can do it? It's very important for me. Thanks for help Link to comment Share on other sites More sharing options...
Olsson Posted January 2, 2009 Share Posted January 2, 2009 I don't quite get what you're looking for - Maybe you could supply us with more information? Link to comment Share on other sites More sharing options...
FireFox Posted January 2, 2009 Share Posted January 2, 2009 @Kubofonista Maybe... While 1 Sleep(50) $wgh = WinGetHandle('', '') TrayTip("Handle Info", $wgh, 0, 1) WEnd Cheers, FireFox. Link to comment Share on other sites More sharing options...
Kubofonista Posted January 2, 2009 Author Share Posted January 2, 2009 I don't quite get what you're looking for - Maybe you could supply us with more information?Im looking for WinGetHandle but not by title or class, by mouse position or mouse click Link to comment Share on other sites More sharing options...
LarryDalooza Posted January 2, 2009 Share Posted January 2, 2009 search "getwindowfrompoint" ... i think AutoIt has helped make me wealthy Link to comment Share on other sites More sharing options...
Kubofonista Posted January 2, 2009 Author Share Posted January 2, 2009 (edited) I'm write code While 1 HotKeySet("{F3}","Gett") HotKeySet("{F4}","Get") HotKeySet("{F5}","Sent") WEnd Func Gett() $wih = WinGetHandle('','') return $wih EndFunc Func Get() $wgh = ControlGetHandle('','','') return $wgh EndFunc Func Sent() global $wgh global $wih WinActive($wih) WinC ControlClick('','',$wgh) ControlSend('','',$wgh,'test') EndFunc But program send only "t" not all word After "t" control is deactivating and next letters is not sending What repair it? Edited January 2, 2009 by Kubofonista Link to comment Share on other sites More sharing options...
Pain Posted January 2, 2009 Share Posted January 2, 2009 Maybe you can use GUIGetCursorInfo $array[4] = ID of the control that the mouse cursor is hovering over (or 0 if none)or as Larry saidhttp://www.autoitscript.com/forum/index.php?showtopic=85175 Link to comment Share on other sites More sharing options...
PsaltyDS Posted January 2, 2009 Share Posted January 2, 2009 (edited) search "getwindowfrompoint" ... i think I came up with "WindowFromPoint", but it returns the handle of the window OR control under the mouse: Opt("MouseCoordMode", 1) HotKeySet("{ESC}", "_Quit") While 1 $avMousePos = MouseGetPos() $avWin = DllCall("user32.dll", "hwnd", "WindowFromPoint", "int", $avMousePos[0], "int", $avMousePos[1]) $hWin = $avWin[0] $sTitle = WinGetTitle($hWin) ToolTip("HWND = " & $hWin & @LF & "Title = " & $sTitle) Sleep(250) WEnd Func _Quit() Exit EndFunc I'm not sure how to differentiate a control from a window, so I can "GetParent" on the controls to get the window handle? Edit: Nevermind... SmOke_N answered that in the same topic with "GetAncestor" using $GW_ROOTOWNER: HotKeySet("{ESC}", "_Quit") While 1 $a_info = _Mouse_Win_GetInfo() If @error Then Exit ToolTip("Handle = " & $a_info[0] & @CRLF & _ "Title = " & $a_info[1] & @CRLF & _ "Mouse X Pos = " & $a_info[2] & @CRLF & _ "Mouse Y Pos = " & $a_info[3]) WEnd Func _Mouse_Win_GetInfo() Local $a_mpos = MouseGetPos() If @error Then Return SetError(1, 0, 0) Local $a_wfp = DllCall("user32.dll", "hwnd", "WindowFromPoint", "long", $a_mpos[0], "long", $a_mpos[1]) If @error Then Return SetError(2, 0, 0) Local $a_ga = DllCall("user32.dll", "hwnd", "GetAncestor", "hwnd", $a_wfp[0], "int", 3); $GW_ROOTOWNER = 3 If @error Then Return SetError(3, 0, 0) Local $a_ret[4] = [$a_ga[0], WinGetTitle($a_ga[0]), $a_mpos[0], $a_mpos[1]] Return $a_ret EndFunc Func _Quit() Exit EndFunc Edited January 2, 2009 by PsaltyDS Valuater's AutoIt 1-2-3, Class... Is now in Session!For those who want somebody to write the script for them: RentACoder"Any technology distinguishable from magic is insufficiently advanced." -- Geek's corollary to Clarke's law Link to comment Share on other sites More sharing options...
charvi Posted January 3, 2009 Share Posted January 3, 2009 (edited) Happy New Year to you (all)! Yes PsaltyDS, this returns the current handle from the cursor point. $avWin = DllCall("user32.dll", "hwnd", "WindowFromPoint", "int", $avMousePos[0], "int", $avMousePos[1]) But how to get the current handle that is currently active? I have searched the Help file and could not find it... Edit: What am I stupid. I found that FireFox wrote it above: $wgh = WinGetHandle('', '') Thanks FireFox! lol Edited January 3, 2009 by charvi Link to comment Share on other sites More sharing options...
FireFox Posted January 3, 2009 Share Posted January 3, 2009 @charvi yep never thing what youre searching for is difficult, its just because you cant do something ... Cheers, FireFox. Link to comment Share on other sites More sharing options...
GreenCan Posted January 3, 2009 Share Posted January 3, 2009 Hi, I played a bit with the scripts provided by PsaltyDS. Pressing delete on buttons of other apps won't help a lot but you can delete the buttons of the own GUI by pressiing Delete. Maybe this could be useful to modify dynamically Menus. I also noticed that WinGetHandle(WinGetTitle($avWin[0])) does the same as the 'GetAncestor' GreenCan expandcollapse popup#include <GuiButton.au3> HotKeySet("{ESC}", "_Quit") HotKeySet("{DELETE}", "deleteobject") $H_GUI = GuiCreate("Windows and object handles", 400, 250) GuiCtrlCreateLabel("Move the mouse over any windo or application", 10, 50, 300, 15) GuiCtrlCreateLabel("and press 'Delete' on an object", 10, 80, 160, 15) GuiCtrlCreateLabel("Press 'Escape' to quit", 10, 110, 160, 15) $btn1 = GUICtrlCreateButton("1", 10, 210, 50, 20) $btn2 = GUICtrlCreateButton("2", 70, 210, 50, 20) $btn3 = GUICtrlCreateButton("3", 130, 210, 50, 20) $btn4 = GUICtrlCreateButton("4", 190, 210, 50, 20) $btn5 = GUICtrlCreateButton("5", 250, 210, 50, 20) $btn6 = GUICtrlCreateButton("6", 310, 210, 50, 20) GUISetState() While 1 $a_info = _Mouse_Win_GetInfo() If @error Then Exit $a_mpos = MouseGetPos() $avWin = DllCall("user32.dll", "hwnd", "WindowFromPoint", "int", $a_mpos[0], "int", $a_mpos[1]) $hWin = $avWin[0] $sTitle = WinGetTitle($hWin) ToolTip("Window: " & @CRLF & "Handle = " & $a_info[0] & @CRLF & _ "Title = " & $a_info[1] & @CRLF & _ "Mouse X Pos = " & $a_info[2] & @CRLF & _ "Mouse Y Pos = " & $a_info[3] & @CRLF & @CRLF & _ "Object (under cursor):" & @CRLF & "Handle = " & $avWin[0] & @CRLF & _ "Title = " & StringLeft($sTitle,100) & @CRLF & _ WinGetHandle(WinGetTitle($avWin[0]))) WEnd Func deleteobject() $avWin = DllCall("user32.dll", "hwnd", "WindowFromPoint", "int", $a_mpos[0], "int", $a_mpos[1]) $hWin = $avWin[0] GuiCtrlCreateLabel("Object " & $avWin[0] & "", 10, 10, 200, 15) If _GUICtrlButton_Destroy($hWin) = True then GuiCtrlCreateLabel("Deleted", 110, 10, 100, 15) GuiCtrlSetColor(-1, 0x006600) Else GuiCtrlCreateLabel("Not Deleted", 110, 10, 100, 15) GuiCtrlSetColor(-1, 0xFF0000) EndIf Return EndFunc Func _Mouse_Win_GetInfo() Local $a_mpos = MouseGetPos() If @error Then Return SetError(1, 0, 0) Local $a_wfp = DllCall("user32.dll", "hwnd", "WindowFromPoint", "int", $a_mpos[0], "int", $a_mpos[1]) If @error Then Return SetError(2, 0, 0) Local $a_ga = DllCall("user32.dll", "hwnd", "GetAncestor", "hwnd", $a_wfp[0], "int", 3); $GW_ROOTOWNER = 3 If @error Then Return SetError(3, 0, 0) Local $a_ret[4] = [$a_ga[0], WinGetTitle($a_ga[0]), $a_mpos[0], $a_mpos[1]] Return $a_ret EndFunc Func _Quit() Exit EndFunc Contributions CheckUpdate - SelfUpdating script ------- Self updating script Dynamic input validation ------------------- Use a Input masks can make your life easier and Validation can be as simple MsgBox with CountDown ------------------- MsgBox with visual countdown Display Multiline text cells in ListView ---- Example of pop-up or ToolTip for multiline text items in ListView Presentation Manager ---------------------- Program to display and refresh different Border-less GUI's on a Display (large screen TV) USB Drive Tools ------------------------------ Tool to help you with your USB drive management Input Period udf ------------------------------ GUI for a period input Excel ColorPicker ---------------------------- Color pickup tool will allow you to select a color from the standard Excel color palette Excel Chart UDF ----------------------------- Collaboration project with water GetDateInString ------------------------------ Find date/time in a string using a date format notation like DD Mon YYYY hh:mm TaskListAllDetailed --------------------------- List All Scheduled Tasks Computer Info --------------------------------- A collection of information for helpdesk Shared memory Demo ----------------------- Demo: Two applications communicate with each other through means of a memory share (using Nomad function, 32bit only) Universal Date Format Conversion -------- Universal date converter from your PC local date format to any format Disable Windows DetailsPane -------------- Disable Windows Explorer Details Pane Oracle SQL Report Generator ------------- Oracle Report generator using SQL SQLite Report Generator ------------------- SQLite Report generator using SQL SQLite ListView and BLOB demo ---------- Demo: shows how binary (image) objects can be recognized natively in a database BLOB field DSN-Less Database connection demo --- Demo: ActiveX Data Objects DSN-Less Database access Animated animals ----------------------------- Fun: Moving animated objects Perforated image in GUI --------------------- Fun: Perforate your image with image objects UEZ's Perforator major update ------------- Fun: Pro version of Perforator by UEZ Visual Crop Tool (GUI) ----------------------- Easy to use Visual Image Crop tool Visual Image effect (GUI) -------------------- Visually apply effects on an image    Link to comment Share on other sites More sharing options...
charvi Posted January 4, 2009 Share Posted January 4, 2009 @GreenCan I also noticed that WinGetHandle(WinGetTitle($avWin[0])) does the same as the 'GetAncestor'Within AutoIt, apparently it does, but when pointing to a non-AutoIt window, it shows Chinese characters (on Vista at least) @FireFox You are right, when my ideas are lost because of a problem, I don't see the solution immediately ;-) Link to comment Share on other sites More sharing options...
GreenCan Posted January 4, 2009 Share Posted January 4, 2009 Hi Charvi, Until now, I got only chinese characters in Scite and Notepad++. In notepad, I see all the text I type in the Title section. In Word the object title is Microsoft Word Document (whatever The content is) Excel gives Book1 in an empty spreadsheet In IE, as I type now, the Object Title remains empty I am still on old fashioned XP GreenCan Contributions CheckUpdate - SelfUpdating script ------- Self updating script Dynamic input validation ------------------- Use a Input masks can make your life easier and Validation can be as simple MsgBox with CountDown ------------------- MsgBox with visual countdown Display Multiline text cells in ListView ---- Example of pop-up or ToolTip for multiline text items in ListView Presentation Manager ---------------------- Program to display and refresh different Border-less GUI's on a Display (large screen TV) USB Drive Tools ------------------------------ Tool to help you with your USB drive management Input Period udf ------------------------------ GUI for a period input Excel ColorPicker ---------------------------- Color pickup tool will allow you to select a color from the standard Excel color palette Excel Chart UDF ----------------------------- Collaboration project with water GetDateInString ------------------------------ Find date/time in a string using a date format notation like DD Mon YYYY hh:mm TaskListAllDetailed --------------------------- List All Scheduled Tasks Computer Info --------------------------------- A collection of information for helpdesk Shared memory Demo ----------------------- Demo: Two applications communicate with each other through means of a memory share (using Nomad function, 32bit only) Universal Date Format Conversion -------- Universal date converter from your PC local date format to any format Disable Windows DetailsPane -------------- Disable Windows Explorer Details Pane Oracle SQL Report Generator ------------- Oracle Report generator using SQL SQLite Report Generator ------------------- SQLite Report generator using SQL SQLite ListView and BLOB demo ---------- Demo: shows how binary (image) objects can be recognized natively in a database BLOB field DSN-Less Database connection demo --- Demo: ActiveX Data Objects DSN-Less Database access Animated animals ----------------------------- Fun: Moving animated objects Perforated image in GUI --------------------- Fun: Perforate your image with image objects UEZ's Perforator major update ------------- Fun: Pro version of Perforator by UEZ Visual Crop Tool (GUI) ----------------------- Easy to use Visual Image Crop tool Visual Image effect (GUI) -------------------- Visually apply effects on an image    Link to comment Share on other sites More sharing options...
charvi Posted January 4, 2009 Share Posted January 4, 2009 Hi GreenCan, I checked further and Notepad gives normal information here. Only Scite is giving Chinese characters, but when I compile your program in EXE (with Beta Compile) I just get a square when I put the mouse cursor on the Scite editor... I have tried AutoIt on both XP and Vista. On XP it works very slowly (excellent for debugging lol), but on Vista it is sensibly a lot faster. While you can see the graphics being drawn on XP, you almost cannot on Vista... Maybe it's the amount of RAM, or higher CPU Speed, I don't know. But I prefer the XP blue window frame than Vista's frames, and that's why I'm faking my applications by copying some XP elements (like the red X close button), giving the look-and-feel of XP on Vista and later on Windows 7 too Cheers, Charvi Link to comment Share on other sites More sharing options...
GreenCan Posted January 4, 2009 Share Posted January 4, 2009 @charvi, Thanks for your feedback. So now the next question is: Should I install Vista now or wait for W7? Contributions CheckUpdate - SelfUpdating script ------- Self updating script Dynamic input validation ------------------- Use a Input masks can make your life easier and Validation can be as simple MsgBox with CountDown ------------------- MsgBox with visual countdown Display Multiline text cells in ListView ---- Example of pop-up or ToolTip for multiline text items in ListView Presentation Manager ---------------------- Program to display and refresh different Border-less GUI's on a Display (large screen TV) USB Drive Tools ------------------------------ Tool to help you with your USB drive management Input Period udf ------------------------------ GUI for a period input Excel ColorPicker ---------------------------- Color pickup tool will allow you to select a color from the standard Excel color palette Excel Chart UDF ----------------------------- Collaboration project with water GetDateInString ------------------------------ Find date/time in a string using a date format notation like DD Mon YYYY hh:mm TaskListAllDetailed --------------------------- List All Scheduled Tasks Computer Info --------------------------------- A collection of information for helpdesk Shared memory Demo ----------------------- Demo: Two applications communicate with each other through means of a memory share (using Nomad function, 32bit only) Universal Date Format Conversion -------- Universal date converter from your PC local date format to any format Disable Windows DetailsPane -------------- Disable Windows Explorer Details Pane Oracle SQL Report Generator ------------- Oracle Report generator using SQL SQLite Report Generator ------------------- SQLite Report generator using SQL SQLite ListView and BLOB demo ---------- Demo: shows how binary (image) objects can be recognized natively in a database BLOB field DSN-Less Database connection demo --- Demo: ActiveX Data Objects DSN-Less Database access Animated animals ----------------------------- Fun: Moving animated objects Perforated image in GUI --------------------- Fun: Perforate your image with image objects UEZ's Perforator major update ------------- Fun: Pro version of Perforator by UEZ Visual Crop Tool (GUI) ----------------------- Easy to use Visual Image Crop tool Visual Image effect (GUI) -------------------- Visually apply effects on an image    Link to comment Share on other sites More sharing options...
charvi Posted January 6, 2009 Share Posted January 6, 2009 @charvi,Thanks for your feedback. So now the next question is: Should I install Vista now or wait for W7? Link to comment Share on other sites More sharing options...
charvi Posted January 6, 2009 Share Posted January 6, 2009 @GreenCan I should recommend you going on Vista. I have sent you a private message. Link to comment Share on other sites More sharing options...
Kubofonista Posted January 11, 2009 Author Share Posted January 11, 2009 I came up with "WindowFromPoint", but it returns the handle of the window OR control under the mouse: Opt("MouseCoordMode", 1) HotKeySet("{ESC}", "_Quit") While 1 $avMousePos = MouseGetPos() $avWin = DllCall("user32.dll", "hwnd", "WindowFromPoint", "int", $avMousePos[0], "int", $avMousePos[1]) $hWin = $avWin[0] $sTitle = WinGetTitle($hWin) ToolTip("HWND = " & $hWin & @LF & "Title = " & $sTitle) Sleep(250) WEnd Func _Quit() Exit EndFunc I'm not sure how to differentiate a control from a window, so I can "GetParent" on the controls to get the window handle? Edit: Nevermind... SmOke_N answered that in the same topic with "GetAncestor" using $GW_ROOTOWNER: HotKeySet("{ESC}", "_Quit") While 1 $a_info = _Mouse_Win_GetInfo() If @error Then Exit ToolTip("Handle = " & $a_info[0] & @CRLF & _ "Title = " & $a_info[1] & @CRLF & _ "Mouse X Pos = " & $a_info[2] & @CRLF & _ "Mouse Y Pos = " & $a_info[3]) WEnd Func _Mouse_Win_GetInfo() Local $a_mpos = MouseGetPos() If @error Then Return SetError(1, 0, 0) Local $a_wfp = DllCall("user32.dll", "hwnd", "WindowFromPoint", "long", $a_mpos[0], "long", $a_mpos[1]) If @error Then Return SetError(2, 0, 0) Local $a_ga = DllCall("user32.dll", "hwnd", "GetAncestor", "hwnd", $a_wfp[0], "int", 3); $GW_ROOTOWNER = 3 If @error Then Return SetError(3, 0, 0) Local $a_ret[4] = [$a_ga[0], WinGetTitle($a_ga[0]), $a_mpos[0], $a_mpos[1]] Return $a_ret EndFunc Func _Quit() Exit EndFunc I'm change it to: Opt("MouseCoordMode", 1) HotKeySet("{ESC}", "_Quit") HotKeySet("{F3}", "_handle") $handle = 0 While 1 $avMousePos = MouseGetPos() $avWin = DllCall("user32.dll", "hwnd", "WindowFromPoint", "int", $avMousePos[0], "int", $avMousePos[1]) $hWin = $avWin[0] $sTitle = WinGetTitle($hWin) ToolTip("HWND = " & $hWin & @LF & "Title = " & $sTitle) WEnd Func _Quit() Exit EndFunc Func _handle() if $handle == 0 Then $handle = $hWin MsgBox(0,0,"Geted handle:"&$hWin) Else controlSend("","",$handle,"string") EndIf EndFunc func _Send() ControlClick("","",$handle) ControlFocus("","",$handle) ControlSend("","",$handle,"string") EndFunc But string is send only if control is active, how send when control is in background? Link to comment Share on other sites More sharing options...
PsaltyDS Posted January 11, 2009 Share Posted January 11, 2009 I'm change it to: Opt("MouseCoordMode", 1) HotKeySet("{ESC}", "_Quit") HotKeySet("{F3}", "_handle") $handle = 0 While 1 $avMousePos = MouseGetPos() $avWin = DllCall("user32.dll", "hwnd", "WindowFromPoint", "int", $avMousePos[0], "int", $avMousePos[1]) $hWin = $avWin[0] $sTitle = WinGetTitle($hWin) ToolTip("HWND = " & $hWin & @LF & "Title = " & $sTitle) WEnd Func _Quit() Exit EndFunc Func _handle() if $handle == 0 Then $handle = $hWin MsgBox(0,0,"Geted handle:"&$hWin) Else controlSend("","",$handle,"string") EndIf EndFunc func _Send() ControlClick("","",$handle) ControlFocus("","",$handle) ControlSend("","",$handle,"string") EndFunc But string is send only if control is active, how send when control is in background? This works fine for me on inactive windows in the background. Exactly what condition fails for you? Valuater's AutoIt 1-2-3, Class... Is now in Session!For those who want somebody to write the script for them: RentACoder"Any technology distinguishable from magic is insufficiently advanced." -- Geek's corollary to Clarke's law Link to comment Share on other sites More sharing options...
LoWang Posted January 20, 2009 Share Posted January 20, 2009 What? Wingethandle gets active window handle by default?! Why isn't it written in help and why didn't you say that FireFox? ;-) This makes things quite easy. Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now