Send double click on tray icon on mouse over?
Send double click on tray icon on mouse over?
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?
Re: Send double click on tray icon on mouse over?
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)
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.
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
Re: Send double click on tray icon on mouse over?
Thanks, i will test the script, but i am not sure if ImageSearch will work because the icon is changing.
Re: Send double click on tray icon on mouse over?
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.
You can also speed up the search by not searching the whole screen when you know it's limited to the tray area.
Re: Send double click on tray icon on mouse over?
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
Hope that helps you guys along.
Greetings
PS: code stops working after I reboot or relog, different var "Ctrol" each time
sorry
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)
}
Greetings
PS: code stops working after I reboot or relog, different var "Ctrol" each time
sorry
Re: Send double click on tray icon on mouse over?
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"
}
Re: Send double click on tray icon on mouse over?
I tested this script but it didn't work. I don't know why, i tested it on icon that is not changing:
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?
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
Who is online
Users browsing this forum: SimmoF and 238 guests