Send double click on tray icon on mouse over?

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
Stark78
Posts: 61
Joined: 03 Oct 2013, 03:17

Send double click on tray icon on mouse over?

10 Feb 2015, 05:30

I want to send double left click on the Comodo firewall icon on the system tray when the mouse is over the icon. Is it possible this to be done without using the icon screen coordinates or mouse coordinates or ImageSearch?
Miguel7
Posts: 186
Joined: 08 Sep 2014, 07:06

Re: Send double click on tray icon on mouse over?

10 Feb 2015, 18:56

To be honest, the easiest way I can think of is exactly what you're saying you don't want to use. There may be other ways, but AFAIK they're a lot more complicated for something that simple. I'm currently learning the Windows UI Automation API, and I might be able to come up with something using that, but even that uses mouse coordinates. There might be some low-level API out there the can do it (some Win32 thing or whatever) but idk enough about that to really be able to say so.

But if it were me, I'd say ImageSearch and coordinates actually make the project a heck of a lot easier (and doable in pure AHK, not even a COM object or DllCall required)

Code: Select all

; First, change a couple settings; maybe not necessary but in all my ImageSearch-intensive projects I find it helps
CoordMode, Mouse, Screen
CoordMode, Pixel, Screen

; Now set up a timer
SetTimer, JustDoIt, 100
return    ; end of auto-run section

; "Label" for the timer 
JustDoIt:

; Get mouse coordinates
MouseGetPos, mouseX, mouseY

; Get icon coordinates 
ImageSearch, iconX, iconY, 0, 0, %A_ScreenWidth%, %A_ScreenHeight%, path\to\the\icon.png

; If the mouse is over the icon, double-click.
; Note: If the icon changes on mouse over, this funky if-statement isn't even necessary (you can just have it search for the image of the icon when the mouse is over it).
if (mouseX > iconX && mouseY > iconY && mouseX < iconX + 20 && mouseY < iconY + 20){
    Click, %mouseX%, %mouseY%, 2
}
return
Anyway, I haven't tested this, but I'm pretty sure it would work. I've done tons of scripts like these, and this is about how I would do it. Hope it helps. :)
Stark78
Posts: 61
Joined: 03 Oct 2013, 03:17

Re: Send double click on tray icon on mouse over?

11 Feb 2015, 07:54

Thanks, i will test the script, but i am not sure if ImageSearch will work because the icon is changing.
User avatar
boiler
Posts: 16963
Joined: 21 Dec 2014, 02:44

Re: Send double click on tray icon on mouse over?

11 Feb 2015, 08:49

You can search for multiple images. Or is it that dynamic that you can't limit it a few cases? Your reference image shouldn't be for the whole icon anyway. It should be for the smallest subset of the image that will uniquely identify it. Often a few pixels are enough. And don't include any transparent areas of the icon as it could change depending on the background behind it.

You can also speed up the search by not searching the whole screen when you know it's limited to the tray area.
wolf_II
Posts: 2688
Joined: 08 Feb 2015, 20:55

Re: Send double click on tray icon on mouse over?

11 Feb 2015, 09:21

I don't have Comodo Firewall to test, I have a Network Monitor in the tray, that I can test with. When that Tray icon gets a double click, it will show a graph, when it gets double-clicked again, that graph gets hidden. Unfortunately, i could not make it to work on mousing over the icon, but when i mouse over the Date/Time area, I can send double clicks to networx.exe. No coordinates used anywhere. Thanks to TrayIcon_Button() in [LIB] TrayIcon.ahk

Code: Select all

#Include TrayIcon.ahk

Loop {
    Loop
        If MouseIsOver_("ahk_class Shell_TrayWnd", Ctrol) && Ctrol = 0x100a2 {
            TrayIcon_Button("networx.exe",, True)
            Break
        }
    Loop
        If !MouseIsOver_("ahk_class Shell_TrayWnd", Ctrol) || Ctrol != 0x100a2
            Break
}


;-------------------------------------------------------------------------------
MouseIsOver_(WinTitle, ByRef Ctrol := 0) { ; from help file, with modifications
;-------------------------------------------------------------------------------
    MouseGetPos,,, Win, Ctrol, 2
    Return, WinExist(WinTitle " ahk_id " Win)
}
Hope that helps you guys along.

Greetings


PS: code stops working after I reboot or relog, different var "Ctrol" each time
sorry
wolf_II
Posts: 2688
Joined: 08 Feb 2015, 20:55

Re: Send double click on tray icon on mouse over?

12 Feb 2015, 05:00

This is slightly better:

Code: Select all

#Include TrayIcon.ahk
Loop {
    Loop
        If MouseIsOver_TrayClock() {
            TrayIcon_Button("networx.exe",, True)
            Break
        }
    Loop
        If !MouseIsOver_TrayClock()
            Break
}
MouseIsOver_TrayClock() {
    MouseGetPos,,,, control
    Return, control = "TrayClockWClass1"
}
Stark78
Posts: 61
Joined: 03 Oct 2013, 03:17

Re: Send double click on tray icon on mouse over?

12 Feb 2015, 15:26

I tested this script but it didn't work. I don't know why, i tested it on icon that is not changing:

Code: Select all

#Persistent

; First, change a couple settings; maybe not necessary but in all my ImageSearch-intensive projects I find it helps
CoordMode, Mouse, Screen
CoordMode, Pixel, Screen

; Now set up a timer
SetTimer, JustDoIt, 100
return    ; end of auto-run section

; "Label" for the timer 
JustDoIt:

; Get mouse coordinates
MouseGetPos, mouseX, mouseY

; Get icon coordinates 
ImageSearch, iconX, iconY, 0, 0, %A_ScreenWidth%, %A_ScreenHeight%, S:\image.jpg

; If the mouse is over the icon, double-click.
; Note: If the icon changes on mouse over, this funky if-statement isn't even necessary (you can just have it search for the image of the icon when the mouse is over it).
if (mouseX > iconX && mouseY > iconY && mouseX < iconX + 20 && mouseY < iconY + 20){
    Click, %mouseX%, %mouseY%, 2
}
return
Is it possible to assign a keyboard shortcut that when pressing it will send double click on the icon, instead when the mouse is over it?

Return to “Ask for Help (v1)”

Who is online

Users browsing this forum: SimmoF and 238 guests