Jump to content

MouseClick, Screen Res and Other Computers


 Share

Recommended Posts

I recently started learning how to use AutoIT and its phenominal, absolutly amazing and i think its going to change the way i use a computer!! so thank you!

i was wondering if anyone would know what i would need to do to sort out a problem - there might be an answer already on the forum but i havnt been able to find it.

run("Program.exe")
MouseClick("secondary", 1177, 1005, 1, 1)
MouseClick("primary", 1108, 841, 1, 1)
Send("{Enter}")

the purpose of this is to run a program, then in the windows tray in the bottom right hand corner (where the sound, time and network status are) the mouse moves to right click on an icon then select something from the list and then press enter. But this works brilliantly on my computer and not on a computer where the screen resolution is anything else. is there anyway of telling the script where the icon is without being dependant on a variable like screen res?

Im not a coder by any stretch of the imagination so please if anyone has any ideas keep them plain and simple in description, i suck at this!

thanks alot in advance!

Link to comment
Share on other sites

#include <GuiButton.au3>
#include <GuiToolBar.au3>

Dim $hButton = ControlGetHandle('[CLASS:Shell_TrayWnd]', '', '[CLASS:Button; INSTANCE:2]')
Dim $hToolBar = ControlGetHandle('[CLASS:Shell_TrayWnd]', '', '[CLASS:ToolbarWindow32]')
Dim $sText

For $i = 0 To _GUICtrlToolbar_ButtonCount($hToolBar)-1
    $sText = _GUICtrlToolbar_GetButtonText($hToolBar, _GUICtrlToolbar_IndexToCommand($hToolBar, $i))
    If $sText = 'volume' Then ExitLoop ; Or other string.
Next

_GUICtrlButton_Click($hButton)
_GUICtrlToolbar_ClickIndex($hToolBar, $i, 'right')

Link to comment
Share on other sites

Hello AJJ. :D

You need to replace the 'volume' with the text of the button of your desired program. If you don't know it you can try the following loop:

#include <GuiToolBar.au3>

Dim $hToolBar = ControlGetHandle('[CLASS:Shell_TrayWnd]', '', '[CLASS:ToolbarWindow32]')
Dim $sText

For $i = 0 To _GUICtrlToolbar_ButtonCount($hToolBar)-1
    ConsoleWrite(_GUICtrlToolbar_GetButtonText($hToolBar, _GUICtrlToolbar_IndexToCommand($hToolBar, $i)) & @LF)
    ;If $sText = 'volume' Then ExitLoop ; ### Or other string. ###
Next

Edit: Or by hovering upon the button with the mouse for a second and using the tooltip text. heh

Edited by Authenticity
Link to comment
Share on other sites

ok then, to summerise:

I have my

run("Program.exe")

first

then

Dim $hToolBar = ControlGetHandle('[CLASS:Shell_TrayWnd]', '', '[CLASS:ToolbarWindow32]')
Dim $sText

For $i = 0 To _GUICtrlToolbar_ButtonCount($hToolBar)-1
    ConsoleWrite(_GUICtrlToolbar_GetButtonText($hToolBar, _GUICtrlToolbar_IndexToCommand($hToolBar, $i)) & @LF)
    If $sText = 'Program Title v1.22' Then ExitLoop; ### Or other string. ###
Next

then what? because i would then need to right click on it and select and option and then left click on it, all potentially on different screen resolutions.

sorry again for sucking so much at this!

but thanks alot for your help!

Edited by AJJ
Link to comment
Share on other sites

A quick and dirty fix

local $coordarray = WinGetPos("Program Manager")
local $desktop_w = $coordarray[2]
local $desktop_h = $coordarray[3] 
local $diff_w = 1280 - $desktop_w
local $diff_h = 1024 - $desktop_h
run("Program.exe")
MouseClick("secondary", 1177 - $diff_w, 1005  - $diff_h, 1, 1)
MouseClick("primary", 1108 - $diff_w, 841 - $diff_h, 1, 1)
Send("{Enter}")

^ That's assuming you running 1280x1024 resolution.

Link to comment
Share on other sites

hey, thanks but this is kinda what i already have, i was wanting to do this on any computer - im guessing that the code above would only work on one screen resolution and not on any.

I think what i need is the whole code (so far i have created my 4 lines (see first post) ) that will select a button in the task bar but that it would know where to go even if the screen res has changed or it is on a different PC.

Then i need to know how to work this code into my exisiting work.

THanks

Link to comment
Share on other sites

ok Quual

what youve put there is actually really good and i now see what youve done but ive realised something else, ofcourse everyone is going to have different items in their program tray, so thats not a good way to do what im trying to do. THANK you though for putting in the code into my code so i could see where it had to go and i could learn from it and understand it!

i guess i need to somehow identify the program specifically but how would i do this ? maybe through task manager, because the AUTOit window info tool shows the label for each item as the same thing so going through the "clicking on the tray item" wont work...

any ideas anyone?

Link to comment
Share on other sites

#include <GuiButton.au3>
#include <GuiToolBar.au3>

Dim $hButton = ControlGetHandle('[CLASS:Shell_TrayWnd]', '', '[CLASS:Button; INSTANCE:2]')
Dim $hToolBar = ControlGetHandle('[CLASS:Shell_TrayWnd]', '', '[CLASS:ToolbarWindow32]')
Dim $sText

For $i = 0 To _GUICtrlToolbar_ButtonCount($hToolBar)-1
    $sText = _GUICtrlToolbar_GetButtonText($hToolBar, _GUICtrlToolbar_IndexToCommand($hToolBar, $i))
    If $sText = 'Program Title v1.22' Then ExitLoop ; Or other string.
Next

_GUICtrlButton_Click($hButton)
_GUICtrlToolbar_ClickIndex($hToolBar, $i, 'right')

; Now a new dialog is created with probably fixed size so you can
; do something like
; W = pop up dialog's width
; H = pop up dialog's height

WinWaitActive('[W:100; H:180]')
Dim $hwnd = WinGetHandle('[W:100; H:180]')
ControlSend($hwnd, '', '', '{UP 3}{ENTER}')

The item you're trying to click on the new dialog is possibly sending WM_COMMAND or similar message so you can try to trace it and just send this message to the process window instead of playing with keystroke or mouse click stuff.

Edited by Authenticity
Link to comment
Share on other sites

i think im understanding this now, ive tried it but taken off the last three lines, and it appears to be working, let me try it on another machine... (it wouldnt work with the last ones on, it selected the options but stopped there.)

Link to comment
Share on other sites

The last 3 lines are there to be more specific with what window get the input. Using AutoIt Window Info, WinSpectorU or WinSpy you can get the dialog dimensions. By the way, this dialog is not in any part a child of the toolbar or the desktop bar. It's a new window created by the 'Program Title v1.22' process.

Edit: Can you post the AutoIt Window Info summary of the new dialog window? It may take a few several attempts but it's possible to capture it.

Edited by Authenticity
Link to comment
Share on other sites

im still not sure what is happening here, is the w198 and h144 is that pixels or a generic coordinate? forgive me for my ignorance, but is $hwnd a variable right? and in this case hwnd is equal to wingethandle (whats a handle?)

also what does @LF mean?

sorry for the probably obvious questions (?) but i think if i can understand the thinking behind it then i will be able to learn it easier. how come youve put in 198 and 144? is that just an example?

Link to comment
Share on other sites

The help file has explanations and examples for this stuff. Search @LF and you'll find that it means LineFeed (sort of C++ \n counterpart).

198 and 144 are not going to help you in any way but to demonstrate how to use this option using the Win* functions. If something is not clear just search the help file, it's a great resource.

Edited by Authenticity
Link to comment
Share on other sites

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 account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...