Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

RE: using AutoItX COM interface

307 views
Skip to first unread message

pjo

unread,
Feb 22, 2008, 6:52:02 AM2/22/08
to

"pjo" wrote:

> Hi! I am trying to control a window application by PowerShell vis AutoItX
> COM interface.
>
> Is there any way to find a button in a Window application in AutoItX com
> interface?
> This button does not have a short cut key as in Firefox bookmark Alt+B.
> So I need to move the mouse to the button and left click. Then select a
> particular item then left click and so on.
>
> pjo
>

I found ControlClick.
ControlClick ( "title", "text", controlID [, button] [, clicks]] )
This will do.
But ControlID for the button must be known.
I tried Au3Info.exe but when the mouse is moved to the button, no
information is displayed.
Does this mean that there is no ControlID for this button ?
Or
Is there any way to find the ControlID ?

pjo

Shay Levi

unread,
Feb 22, 2008, 7:39:39 AM2/22/08
to

In your AutoIT directory you'll find a file "Au3Info.exe". Launch it and
hover around your window (button)
You'll see all the information you need.

Tip: Press CTRL-ALT-F to freeze the display.

-----
Shay Levi
$cript Fanatic
http://scriptolog.blogspot.com

pjo

unread,
Feb 22, 2008, 5:45:39 PM2/22/08
to
Thanks Shay,

But as I described in my previous post,

> I tried Au3Info.exe but when the mouse is moved to the button, no
> information is displayed.
> Does this mean that there is no ControlID for this button ?
> Or
> Is there any way to find the ControlID

Au3Info.exe is runnong here and it showed no information when the mouse is
moved to the button even with freeze enabled.

Is there any other way to click this button. Maybe by making the app window
to max and do mouse move command ?

pjo

Shay Levi

unread,
Feb 22, 2008, 6:26:34 PM2/22/08
to

Two options:

1. Launch a fresh copy of the window and hit TAB repeatedly until the button
gets in focus, count the hopes. Then you can use use the Send() method
to SendKeys to the window:

Send ("{TAB 3}{ENTER}")
# this performs 3 times TAB and then ENTER.

2. Search the help for "MouseCoordMode". It's a global AutoIT option. It
sets the way coords are used in the mouse functions, either absolute coords
or coords relative to the current active window:
0 = relative coords to the active window
1 = absolute screen coordinates (default)
2 = relative coords to the client area of the active window

The "Window" option is safer to use because computer can be set to different
resolution.
Now, in Au3info.exe menu, goto Options > coord mode > and Activate "Window",
hover your mouse over the button and locate this section:

>>>>>>>>>>> Mouse Details <<<<<<<<<<<
Window: X: 175 Y: 517
Cursor ID: 5

It tells you the button coordinates with respect to the active window. To
*click* that button:

Opt("MouseCoordMode", 0)
MouseMove(175,517)
MouseDown("left")

; switch back to the default
Opt("MouseCoordMode", 0)

Shay Levi

unread,
Feb 22, 2008, 6:31:50 PM2/22/08
to

Had a typo :(

; switch back to the default

Opt("MouseCoordMode", 1)

pjo

unread,
Feb 22, 2008, 6:44:01 PM2/22/08
to
Thanks Shay again.

I will try this and report here about results.

Can I write the followings in PoerShell script ?

Opt("MouseCoordMode", 0)
MouseMove(175,517)
MouseDown("left")

pjo

unread,
Feb 22, 2008, 6:51:01 PM2/22/08
to
Thanks Shay,

Can I write the followings in PoerShell script ?

Opt("MouseCoordMode", 1)
MouseMove(175,517)
MouseDown("left")

pjo

unread,
Feb 22, 2008, 6:53:00 PM2/22/08
to
Thanks Shay,

Can I write the followings in PoerShell script ?

Opt("MouseCoordMode", 1)
MouseMove(175,517)
MouseDown("left")

Shay Levi

unread,
Feb 22, 2008, 6:44:29 PM2/22/08
to
This commands are for .AU3 script. I'll try to find how they can be written
with the automation dll.

pjo

unread,
Feb 22, 2008, 6:57:02 PM2/22/08
to
> 1. Launch a fresh copy of the window and hit TAB repeatedly until the button
> gets in focus, count the hopes. Then you can use use the Send() method
> to SendKeys to the window

By issueing TABs the button does not gets in focus.

I will try the other method,

Shay Levi

unread,
Feb 22, 2008, 7:35:22 PM2/22/08
to

Here's the PowerShell version:

$autoIt = new-object -com AutoItX3.Control
$autoIt.Opt("MouseCoordMode", 1)
$autoIt.MouseMove(175,517)
$autoIt.MouseDown("left")

# switch back to screen coordinates (default)
$autoIt.Opt("MouseCoordMode", 0)

Shay Levi

unread,
Feb 22, 2008, 7:46:02 PM2/22/08
to
Ops... I did it again, it's already 03:00 AM, time to start-sleep :)

The first opt should be 0 (Window) and the second is 1 (default)

pjo

unread,
Feb 22, 2008, 8:09:00 PM2/22/08
to
Thanks Shay,

I figured it out.

Now it is working.

I will search how to browse down the pull down menu, tree items down.

pjo

pjo

unread,
Feb 23, 2008, 7:22:00 PM2/23/08
to
Hi! I am stuck again.

The application is maximized by Alt+ Space + X
because if the app window is not maximized the coordinates for the menu item
is different each time when it is activated.
A window within the appliation is opened.
I want to maximize this inner window but his app does not have a hotkey to
do this.
The inner window has the standard icon to minimize, maximize, exit at the
upper right corner.
I am trying to click maximize button but again the location when this inner
window is opened is different a little bit each time so the mousemove command
does not work most of the time.

Please advise some hint to solve this problem.
Is there any way to maximize the inner window with AutoIt command or at
least move to the upper left edge ?

pjo

unread,
Feb 23, 2008, 9:15:00 PM2/23/08
to
The inner windows information in Au3Info.exe:

Basic Control Info AfxFrameOrView42
instance 45
ClassnameNN AfxFrameOrView4245
ID 59648
Text
Position 810, 54
Size 211,473
ControlClick Coords 203,96
Style 0x50000000
ExStyle 0x00000200
Handle 0x00031618

pjo

unread,
Feb 23, 2008, 9:38:00 PM2/23/08
to
The other point:
A tiny dialogue box to input characters is opened in the lower left corner
of the inner window by issuing Ctrl + SPACE.
At this point the cursor is blinking and the mouse pointer is somewhere else.
How can the mouse pointer move to the character cursor to input characters?

In manual mode there is no need to move mouse pointer to the cursor to input
character at this cursor. Just type in then charcters are input to this
dialogue.

Shay Levi

unread,
Feb 24, 2008, 2:44:05 AM2/24/08
to

You can use the "WinSetState()" method to maximize the window.

Shay Levi

unread,
Feb 24, 2008, 2:51:43 AM2/24/08
to

You can ignore the mouse location and *write* yur text directly to the textbox.
It doesn't matter if the control/dialog box is in focus or not:

ControlSetText ( "title", "text", controlID, "new text" [, flag] )

pjo

unread,
Feb 24, 2008, 3:38:01 AM2/24/08
to
Thanks Shay,


Can I issue

ControlSetText ( "title", "text", controlID, "new text" [, flag] )

to the inner window which does not have controlID ?

Or is it in the au35nfo window ?

pjo

unread,
Feb 24, 2008, 3:39:00 AM2/24/08
to
WinSetState ( "title", "text", flag )

this requires "title" but the inner window does not have title.

pjo

unread,
Feb 24, 2008, 6:07:00 AM2/24/08
to
I tried:
$autoitx.ControlSetText( "EURISD,H1", "",59648 , "M15+{ENTER}")

nut nothing happened.
Maybe ControlID is wrong for the inner window.

Shay Levi

unread,
Feb 24, 2008, 6:14:29 AM2/24/08
to
try to set the ClassnameNN "AfxFrameOrView4245" as the ID:

$autoitx.ControlSetText( "EURISD,H1", "","AfxFrameOrView4245" , "M15+{ENTER}")

pjo

unread,
Feb 24, 2008, 10:22:00 AM2/24/08
to
I also tried to double click the top bar which has focus:

$autoitx.ControlClick("","","[CLASNN:AfxFrameOrView425]","LEFT",2)

this returns 0 which is failure.

pjo

unread,
Feb 24, 2008, 10:27:04 AM2/24/08
to
$autoitx.ControlClick("","","AfxFrameOrView425","LEFT",2)
this works sometime.

Sending Alt+1
$autoitx.ControlSetText("","","AfxFrameOrView425","{ALT}+1")
or
$autoitx.ControlSetText("","","AfxFrameOrView425","{ALT}1")
which is correct ?

pjo

unread,
Feb 24, 2008, 10:48:01 AM2/24/08
to
There is a typo

$autoitx.ControlSend("","","AfxFrameOrView4245","{ALT}+1")
this returns 1
but the result is nothing, I mean nothing was changed in the window.

Shay Levi

unread,
Feb 24, 2008, 11:01:47 AM2/24/08
to

Is the window your working on is a system window, which I can test, or is
it a custom application window?

pjo

unread,
Feb 24, 2008, 5:21:01 PM2/24/08
to
The app I am working on was developed by MetaQuote, and the name is Meta
Trader 4.

pjo

unread,
Feb 24, 2008, 6:08:00 PM2/24/08
to
BTW MT4 is free but requires registration.

pjo

unread,
Feb 24, 2008, 9:19:00 PM2/24/08
to
Hello !

Finally I got it working !
$autoitx.ControlSend("","",59648,"!1")

$autoitx.ControlSetText("","","AfxFrameOrView4245","{ALT}+1")
this was not sending ALT+1

pjo

unread,
Mar 10, 2008, 12:21:01 PM3/10/08
to
Hi! I have been working on this script.

# $autoitx.Send("!1") Alt + 1 is asssigned to SterEA....


$autoitx.ControlSend("", "",59648,"!1")

# uncheck Confirm
$autoitx.ControlClick("", "",1064,"LEFT")

# Click OK
$autoitx.ControlClick("", "",1,"LEFT")

The ControlClick works sometime, not always.
I am wondering why.

By using Au3Info.exe the window Control ID is taken in the Control tab of
the Au3Info.
What would be the cause of this phenomena ?

pjo

Shay Levi

unread,
Mar 10, 2008, 12:33:19 PM3/10/08
to
Try to sleep between clicks.

-----
Shay Levi
$cript Fanatic
http://scriptolog.blogspot.com

> Hi! I have been working on this script.

pjo

unread,
Mar 10, 2008, 8:15:00 PM3/10/08
to
Thanks Shay,

It worked !
Your comments are always superb !

pjo

pjo

unread,
Mar 11, 2008, 7:32:00 AM3/11/08
to
Using Windows standard key stroke to minimize a window,
Alt+-+n works fine if inputed using keyboard.

But

Start-Sleep 2
$autoitx.ControlSend("","",59648,"!-")
# Start-Sleep -Milliseconds 500
$autoitx.ControlSend("","",59648,"n")

This does not work for the same window.

Please advise how to do this ?
----------------------------------
The other question is:
After opening a window is there any way to get the control ID of that window
in AutoitX ?

pjo

Shay Levi

unread,
Mar 11, 2008, 7:42:54 AM3/11/08
to

Hi

You can also use the AutoIT's sleep function:

$autoitx.Sleep(x) #milliseconds

To minimize a window (blank notepad window):
$autoitx.WinSetState("Untitled -", "", $autoitx.SW_MINIMIZE)

pjo

unread,
Mar 11, 2008, 9:14:00 AM3/11/08
to
Thanks Shay,

Since the window is a window within that application window,
I am trying to access it as CLASS,

$autoitx.WinSetState("[CLASS:AfxFrameOrView42]", "", $autoitx.SW_MINIMIZE)

But this does not work.

Any idea ?

pjo

Shay Levi

unread,
Mar 11, 2008, 9:20:29 AM3/11/08
to

The first parameter is for the window title so I don't think it will work
the way you suggested:

WinSetState "title", "text", flag

Can you think of an equivalent system window (XP) that has MDI windows I
can test?
Can you minimize it by mouse clicks?

pjo

unread,
Mar 11, 2008, 9:52:02 AM3/11/08
to
Yes.

Window within a windows app is this one I am working on, which is
MetaTrader 4 from MetaQuote, this is free, registration is required.

The url is
http://www.alpari-idc.com/

No money payment is required for a demo account.
As a default setting you will see four window in MT4, I think.

Yes I can minimize it with mouse click.
But again it will be difficult to move mouse to minimize button.

pjo

Shay Levi

unread,
Mar 12, 2008, 5:25:43 AM3/12/08
to

Try to set coord mode to "Window", use Au3Info.exe to pick the mouse coordinates
and then
send a mouse click. It shouldn't be that hard to implement.

Joel (Jaykul) Bennett

unread,
Mar 14, 2008, 11:25:26 PM3/14/08
to
You guys might want to check out:

http://CodePlex.com/WASP/ which is specifically for automating windows
in PowerShell
http://CodePlex.com/White/ which is a .net windows automation package

0 new messages