sausme Posted September 22, 2010 Share Posted September 22, 2010 Hi there!!I'm new using AutoIt and have some trouble with the syntax of the ControlID instruction:I'm writing the following:$aPosControl=ControlGetPos($sWinQp,$sWinQpText,"[X:1; Y:1]")It means the control position is (1,1)The problem is that it does not work!! I'm using the Help File as reference:ID - The internal control ID. The Control ID is the internal numeric identifier that windows gives to each control. It is generally the best method of identifying controls. In addition to the AutoIt Window Info Tool, other applications such as screenreaders for the blind and Microsoft tools/APIs may allow you to get this Control ID TEXT - The text on a control, for example "&Next" on a button CLASS - The internal control classname such as "Edit" or "Button" CLASSNN - The ClassnameNN value as used in previous versions of AutoIt, such as "Edit1" NAME - The internal .NET Framework WinForms name (if available) REGEXPCLASS - Control classname using a regular expression X \ Y \ W \ H - The position and size of a control. INSTANCE - The 1-based instance when all given properties match. I need help using the bold quotation in the property field in the ControlID field of the ControlGetPos function.Thank you for reading (and of course, answering !!) Link to comment Share on other sites More sharing options...
BrewManNH Posted September 22, 2010 Share Posted September 22, 2010 You're looking at the wrong information for ControlGetPos, you use this command to GET the controls position, not set it. I'm not sure which description you're looking at with the above information, but the description for ControlGetPos shows ControlGetPos ( "title", "text", controlID ) for what it's looking for, for parameters. If I posted any code, assume that code was written using the latest release version unless stated otherwise. Also, if it doesn't work on XP I can't help with that because I don't have access to XP, and I'm not going to.Give a programmer the correct code and he can do his work for a day. Teach a programmer to debug and he can do his work for a lifetime - by Chirag GudeHow to ask questions the smart way! I hereby grant any person the right to use any code I post, that I am the original author of, on the autoitscript.com forums, unless I've specifically stated otherwise in the code or the thread post. If you do use my code all I ask, as a courtesy, is to make note of where you got it from. Back up and restore Windows user files _Array.au3 - Modified array functions that include support for 2D arrays. - ColorChooser - An add-on for SciTE that pops up a color dialog so you can select and paste a color code into a script. - Customizable Splashscreen GUI w/Progress Bar - Create a custom "splash screen" GUI with a progress bar and custom label. - _FileGetProperty - Retrieve the properties of a file - SciTE Toolbar - A toolbar demo for use with the SciTE editor - GUIRegisterMsg demo - Demo script to show how to use the Windows messages to interact with controls and your GUI. - Latin Square password generator Link to comment Share on other sites More sharing options...
sausme Posted September 22, 2010 Author Share Posted September 22, 2010 Hi! Thanks for answering so fast!I'm using [X:1; Y:1] to identify the control that is in the position (1,1). I could use the [CLASS:MyClass; INSTANCE:MyInstance] structure but it does not work for my script since my window is contstantly creating new controls with the same Class and Instance properties, so I'm tring to identify my control with its position. The thing is that I'm not quite sure about how to make reference to the control's position from the ControlGetPos() function.Sorry if I wasn't clear enough earlier Link to comment Share on other sites More sharing options...
Mat Posted September 22, 2010 Share Posted September 22, 2010 You need to use ChildWindowFromPoint to get the handle if the control / window is hidden, or you can use WindowFromPoint if it's shown. AutoIt Project Listing Link to comment Share on other sites More sharing options...
sausme Posted September 22, 2010 Author Share Posted September 22, 2010 Let's change the function to make it clearer: Assume I want to use ControlClick() instead of ControlGetPos(): I could use: ControlClick("MyWindow", "MyWindowText", "[Class:MyClass; INSTANCE:MyInstace]") Insted, I want to use something like: ControlClick("MyWindow", "MyWindowText", "[X:1; Y:1]") to make reference to the control's position, not to the control's Class and Instance. As you see the problem is in the way I write de ControlID field, in spite that it's clear (as it's remarked in the help file) that the position could be used as a special property to make reference to. Link to comment Share on other sites More sharing options...
Mat Posted September 22, 2010 Share Posted September 22, 2010 Let's change the function to make it clearer: Assume I want to use ControlClick() instead of ControlGetPos(): I could use: ControlClick("MyWindow", "MyWindowText", "[Class:MyClass; INSTANCE:MyInstace]") Insted, I want to use something like: ControlClick("MyWindow", "MyWindowText", "[X:1; Y:1]") to make reference to the control's position, not to the control's Class and Instance. As you see the problem is in the way I write de ControlID field, in spite that it's clear (as it's remarked in the help file) that the position could be used as a special property to make reference to. That's not mentioned anywhere in the helpfile, and doesn't work... So no. You can't do that My method above is the only way I know to do it. AutoIt Project Listing Link to comment Share on other sites More sharing options...
BrewManNH Posted September 22, 2010 Share Posted September 22, 2010 Is your control actually at position 1,1? If it's not then this won't work. To make sure that you're clicking the correct control, and in the correct location, you should use the AU3Info.exe tool and get this information. Relying on a control's position is not the best way to go about clicking on it, because it might not be there when you try to click it. Use the actual ID # if you can, or one of the other less changeable parameters. If I posted any code, assume that code was written using the latest release version unless stated otherwise. Also, if it doesn't work on XP I can't help with that because I don't have access to XP, and I'm not going to.Give a programmer the correct code and he can do his work for a day. Teach a programmer to debug and he can do his work for a lifetime - by Chirag GudeHow to ask questions the smart way! I hereby grant any person the right to use any code I post, that I am the original author of, on the autoitscript.com forums, unless I've specifically stated otherwise in the code or the thread post. If you do use my code all I ask, as a courtesy, is to make note of where you got it from. Back up and restore Windows user files _Array.au3 - Modified array functions that include support for 2D arrays. - ColorChooser - An add-on for SciTE that pops up a color dialog so you can select and paste a color code into a script. - Customizable Splashscreen GUI w/Progress Bar - Create a custom "splash screen" GUI with a progress bar and custom label. - _FileGetProperty - Retrieve the properties of a file - SciTE Toolbar - A toolbar demo for use with the SciTE editor - GUIRegisterMsg demo - Demo script to show how to use the Windows messages to interact with controls and your GUI. - Latin Square password generator Link to comment Share on other sites More sharing options...
BrewManNH Posted September 22, 2010 Share Posted September 22, 2010 That's not mentioned anywhere in the helpfile, and doesn't work... So no. You can't do that My method above is the only way I know to do it.Actually that method is listed in the help file, the 3rd parameter for ControlClick is the Control ID, if you click on the hyperlink for Controls in that you'll see where he got that information from. I don't remember ever seeing that myself, but I finally found it. If I posted any code, assume that code was written using the latest release version unless stated otherwise. Also, if it doesn't work on XP I can't help with that because I don't have access to XP, and I'm not going to.Give a programmer the correct code and he can do his work for a day. Teach a programmer to debug and he can do his work for a lifetime - by Chirag GudeHow to ask questions the smart way! I hereby grant any person the right to use any code I post, that I am the original author of, on the autoitscript.com forums, unless I've specifically stated otherwise in the code or the thread post. If you do use my code all I ask, as a courtesy, is to make note of where you got it from. Back up and restore Windows user files _Array.au3 - Modified array functions that include support for 2D arrays. - ColorChooser - An add-on for SciTE that pops up a color dialog so you can select and paste a color code into a script. - Customizable Splashscreen GUI w/Progress Bar - Create a custom "splash screen" GUI with a progress bar and custom label. - _FileGetProperty - Retrieve the properties of a file - SciTE Toolbar - A toolbar demo for use with the SciTE editor - GUIRegisterMsg demo - Demo script to show how to use the Windows messages to interact with controls and your GUI. - Latin Square password generator Link to comment Share on other sites More sharing options...
sausme Posted September 23, 2010 Author Share Posted September 23, 2010 Is your control actually at position 1,1? If it's not then this won't work. To make sure that you're clicking the correct control, and in the correct location, you should use the AU3Info.exe tool and get this information. Relying on a control's position is not the best way to go about clicking on it, because it might not be there when you try to click it. Use the actual ID # if you can, or one of the other less changeable parameters. Yes, I'm using the AU3Info tool to be sure about the control's position, and tried before using another (more trustable) property like the ID#, the handle or the Class/Instance, but, as I posted earlier, none of those worked since my window (actually a form) is creating a new control each time I press the Tab key - to pass from one field (control, for AutoIt) of the form to the next one-. The active field has always the properties [Class:Edit; INSTANCE:1], no matter if I'm on the first or the last field of the form, so the only way I can think of to make reference to the exact field is by its position which will never change Link to comment Share on other sites More sharing options...
BrewManNH Posted September 23, 2010 Share Posted September 23, 2010 Well, if the control you're looking for is at 1,1, then you don't need ControlGetPos, because you already HAVE the Pos part of that function. You might want to look at using ControlGetHandle using the X,Y coordinates, depending upon what your script is doing with the control that you're looking at. If I posted any code, assume that code was written using the latest release version unless stated otherwise. Also, if it doesn't work on XP I can't help with that because I don't have access to XP, and I'm not going to.Give a programmer the correct code and he can do his work for a day. Teach a programmer to debug and he can do his work for a lifetime - by Chirag GudeHow to ask questions the smart way! I hereby grant any person the right to use any code I post, that I am the original author of, on the autoitscript.com forums, unless I've specifically stated otherwise in the code or the thread post. If you do use my code all I ask, as a courtesy, is to make note of where you got it from. Back up and restore Windows user files _Array.au3 - Modified array functions that include support for 2D arrays. - ColorChooser - An add-on for SciTE that pops up a color dialog so you can select and paste a color code into a script. - Customizable Splashscreen GUI w/Progress Bar - Create a custom "splash screen" GUI with a progress bar and custom label. - _FileGetProperty - Retrieve the properties of a file - SciTE Toolbar - A toolbar demo for use with the SciTE editor - GUIRegisterMsg demo - Demo script to show how to use the Windows messages to interact with controls and your GUI. - Latin Square password generator Link to comment Share on other sites More sharing options...
sausme Posted September 23, 2010 Author Share Posted September 23, 2010 Well, if the control you're looking for is at 1,1, then you don't need ControlGetPos, because you already HAVE the Pos part of that function. You might want to look at using ControlGetHandle using the X,Y coordinates, depending upon what your script is doing with the control that you're looking at.That's right: I don't need ControlGetPos, that's why I changed the example . Assume then that I need ControlClick() In that case I would need the ControlID too, and the only thing I have to make referece to that control is its position. I've alredy tried with the handle, but it does not work either Link to comment Share on other sites More sharing options...
Mat Posted September 23, 2010 Share Posted September 23, 2010 Maybe you need to supply the width and height as well?? AutoIt Project Listing Link to comment Share on other sites More sharing options...
sausme Posted September 23, 2010 Author Share Posted September 23, 2010 Maybe you need to supply the width and height as well?? I've already done something like: ControlClick("MyWindow","MyWindowText","[X:MyXPos; Y:MyYPos; W:MyWidth; H:MyHight]") ;or somethig like ControlClick("MyWindow","MyWindowText","[X:MyXPos, Y:MyYPos, W:MyWidth, H:MyHight]") None of those work The funny thing is that that AutoIt runs that sentence without any error, like if it was identifing some control, just not the one I need. Link to comment Share on other sites More sharing options...
Sticky Posted September 23, 2010 Share Posted September 23, 2010 (edited) I've already done something like: ControlClick("MyWindow","MyWindowText","[X:MyXPos; Y:MyYPos; W:MyWidth; H:MyHight]") ;or somethig like ControlClick("MyWindow","MyWindowText","[X:MyXPos, Y:MyYPos, W:MyWidth, H:MyHight]") None of those work The funny thing is that that AutoIt runs that sentence without any error, like if it was identifing some control, just not the one I need. Have you tried something like: ControlClick("MyWindow","MyWindowText","","left", 1, 1, 1) Sometimes the x, y location may be offset by using the previous method, it's helped me to use something like the following to see where the offsets actually click. For $i = 1 To 150 MsgBox(4096, "Clicking...", "x: "&$i&", y: "&$i) ControlClick("MyWindow","MyWindowText","","left",1, $i, $i) Next Or if tabbing is all you need, then try: ControlSend("MyWindow", "MyWindowText", "", "{TAB}") Edited September 23, 2010 by Sticky Link to comment Share on other sites More sharing options...
Malkey Posted September 24, 2010 Share Posted September 24, 2010 This example might help. ; Example X \ Y \ W \ H - The position and size of a control. $calcHWND = WinGetHandle("[CLASS:SciCalc]") If $calcHWND = "" Then Run("calc.exe") WinActivate("[CLASS:SciCalc]", "") WinWaitActive("[CLASS:SciCalc]", "") ControlClick("[CLASS:SciCalc]", "", "[X:234;Y:98]") ; Button 7 X, Y is 234, 98 Sleep(2000) ControlClick("[CLASS:SciCalc]", "", "[X:273;Y:98]") ; Button 8 X, Y is 273, 98 Sleep(2000) Local $x = 312 Local $y = 98 ControlClick("Calculator", "", "[X:" & $x & ";Y:" & $y & "]") ; Button 9 X, Y is 312, 98 Link to comment Share on other sites More sharing options...
sausme Posted September 24, 2010 Author Share Posted September 24, 2010 This example might help. ; Example X \ Y \ W \ H - The position and size of a control. $calcHWND = WinGetHandle("[CLASS:SciCalc]") If $calcHWND = "" Then Run("calc.exe") WinActivate("[CLASS:SciCalc]", "") WinWaitActive("[CLASS:SciCalc]", "") ControlClick("[CLASS:SciCalc]", "", "[X:234;Y:98]") ; Button 7 X, Y is 234, 98 Sleep(2000) ControlClick("[CLASS:SciCalc]", "", "[X:273;Y:98]") ; Button 8 X, Y is 273, 98 Sleep(2000) Local $x = 312 Local $y = 98 ControlClick("Calculator", "", "[X:" & $x & ";Y:" & $y & "]") ; Button 9 X, Y is 312, 98 Is that code actually working for you? I'm using that exact same structure of the ControlID parameter: [Property1:Value1;Property2;Value2; ... ] or [X:206;Y:129] (in my calc, button 7 is at the (206,129) position) The control is just not clicked and the return value of the ControlClick() function is 0. I wonder if there is any AutoIt option that must be set in order to make it work. Link to comment Share on other sites More sharing options...
sausme Posted September 24, 2010 Author Share Posted September 24, 2010 I just tried this and worked: Run("notepad.exe") WinWaitActive("[CLASS:Notepad]") controlsend("[CLASS:Notepad]","","[X:0;Y:0]","This is actually working") sleep(3000) WinKill("[CLASS:Notepad]") It means that the ControlID structure is ok. It seems that it only works a ) If the control is at the (0,0) position b ) Only works with the notepad Has anybody tried to use that ControlID structure with other apps? Link to comment Share on other sites More sharing options...
Malkey Posted September 24, 2010 Share Posted September 24, 2010 Is that code actually working for you? ....Yes, also your ControlSend to Notepad works on my xp. Link to comment Share on other sites More sharing options...
sausme Posted September 24, 2010 Author Share Posted September 24, 2010 (edited) So I can't figure out where the problem is. The ControlID structure is ok but I can only make it work in notepad Edited September 24, 2010 by sausme 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