Jump to content
Sign in to follow this  
AJJ

MouseClick, Screen Res and Other Computers

Recommended Posts

AJJ

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!

Share this post


Link to post
Share on other sites
Authenticity

#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')

Share this post


Link to post
Share on other sites
AJJ

hmm, what exactly is happening here and wheres the variable for me to change?

Share this post


Link to post
Share on other sites
Authenticity

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

Share this post


Link to post
Share on other sites
AJJ

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

Share this post


Link to post
Share on other sites
Quual

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.

Share this post


Link to post
Share on other sites
AJJ

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

Share this post


Link to post
Share on other sites
AJJ

also, apart from the three on the AUTOit documentation are there any other tutorials around ebcause they were really useful!

Share this post


Link to post
Share on other sites
AJJ

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?

Share this post


Link to post
Share on other sites
Authenticity

#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

Share this post


Link to post
Share on other sites
AJJ

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.)

Share this post


Link to post
Share on other sites
AJJ

thats weird, it does work on the other computer ( a wide screen one) but only 1 out of 5 times, i cant see what the issue is, either it should work or it shouldnt...

Share this post


Link to post
Share on other sites
Authenticity

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

Share this post


Link to post
Share on other sites
AJJ

how would i do that?

Share this post


Link to post
Share on other sites
Authenticity

Use WinSpy, I can successfully capture these dialog windows using WinSpy.

Edit: This tool can also show information like dimensions or class name, etc...

Edited by Authenticity

Share this post


Link to post
Share on other sites
AJJ

winspy eh? i have autoit v3 window info already installed, can i not do it with that? (dont want to install another thing, but will do if nessecary !)

Share this post


Link to post
Share on other sites
Authenticity

lol Do whatever you want. It's your decision if you want your script to be more specific or not. For me it's working perfectly:

WinWait('[W:198; H:144]')
$hwnd  = WinGetHandle('[W:198; H:144]')
ConsoleWrite($hwnd & @LF)

And no window on my system has this exact dimensions.

Share this post


Link to post
Share on other sites
AJJ

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?

Share this post


Link to post
Share on other sites
Authenticity

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

Share this post


Link to post
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
Sign in to follow this  

×