AutoHotkey Community

It is currently May 27th, 2012, 12:31 pm

All times are UTC [ DST ]




Post new topic Reply to topic  [ 51 posts ]  Go to page 1, 2, 3, 4  Next
Author Message
PostPosted: February 17th, 2009, 6:48 pm 
Offline

Joined: February 15th, 2009, 5:37 pm
Posts: 4
I need to automate temporary disabling COMODO CIS Defense+ during backup run.
There is no commandline switch to do this, but can be done via taskbar tray-icon.

So I need a hint about the proper command(s) to code it myself.
I want to find the tray-icon with text 'COMODO Internet Security' and perform mouse-clicks on it/submenus. Is it possible with AHK?

I tried with AutoSCriptWriter and AU3-Spy, but did not succeed.

Since there's initially no window to focus on and send relative mouseclick coordinates to, my approach does not work :(

I want to do this:
Now I have automated my backups and Defense+ shows dozens of messages for me to decide to allow/disallow them. As I use Cygwin Linux-emulation under Windows, the tools should not universally be allowed, so I must disable Defense+ first or the backups won't run. I can do this manually via the GUI in taskbar 'Defense+ Security Level -> Disabled'.


Report this post
Top
 Profile  
Reply with quote  
 Post subject: Please be specific
PostPosted: February 18th, 2009, 4:54 am 
Offline

Joined: September 14th, 2005, 4:55 pm
Posts: 34
Location: Japan
Hi,
it is difficult to understand what you want to do. I suppose you want to "answer" dialogues with AHK?
Then make a list of all Dialogues and what you want to do with them. Use WindowSpy (ahk tray icon right click) and memorize all dialogue's ahk classes (if they are identicall additionla also their Window title)

You can then create a macro which answers those dialogues by sending keystrkes or mouseclick to the buttons or controls you like.
You can use WinWait to wait for a secific dialogue and you can use IfWinExist to see if it is there. Then you can use ControlSend,,KEYS,TARGET (omit second parameter)...


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: February 18th, 2009, 1:42 pm 
Offline

Joined: February 15th, 2009, 5:37 pm
Posts: 4
Hi UweD,

thanks for your reply.

I have read the tutorials,FAQs and basically know how to automate dialogs/Windows actions with AHK, but do not know how to operate on non-Windows, like the taskbar tray-icon:

I tested it this way:

Code:
IfWinExist COMODO Internet Security
{
    WinActivate
}
else
{
  MsgBox Cannot find Window 'COMODO Internet Security'!!
}


=> Not working, the messagebox in the else-clause is shown.

----
Output of WindowsSpy:
## right click on TrayIcon (the action I want) ##

Code:
>>>>>>>>>>( Window Title & Class )<<<<<<<<<<<
COMODO Internet Security
ahk_class #32770

>>>>>>>>>>>>( Mouse Position )<<<<<<<<<<<<<
On Screen:   859, 333  (less often used)
In Active Window:   -421, 105

>>>>>>>>>( Now Under Mouse Cursor )<<<<<<<<

Color:   0xC8D0D4  (Blue=C8 Green=D0 Red=D4)

>>>>>>>>>>( Active Window Position )<<<<<<<<<<
left: 1280     top: 228     width: 788     height: 544

>>>>>>>>>>>( Status Bar Text )<<<<<<<<<<

>>>>>>>>>>>( Visible Window Text )<<<<<<<<<<<
SUMMARY
FIREWALL
DEFENSE+
MISCELLANEOUS
ANTIVIRUS
Common Tasks
View Antivirus Events
Run a Scan
Scan Profiles

[... 150 additional lines deleted]

>>>>>>>>>>>( Hidden Window Text )<<<<<<<<<<<
Proactive Defense
The Defense+ has blocked
suspicious attempt(s) so far.
0
Run Diagnostics

>>>>( TitleMatchMode=slow Visible Text )<<<<

>>>>( TitleMatchMode=slow Hidden Text )<<<<


Can I still automate this with AHK?

To understand this better, I have made a screenshot of the TrayIcon part and the opened menu I want to script:
http://neodor.com/auctions/TrayIcon_CIS_2-Monitors.PNG

The TrayIcon directly next to the windows clock (the shield icon) is the CIS icon I want to automate. Everything on the right side of the windows clock is the second monitor, so my desktop/working area is two panels wide.


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: February 18th, 2009, 3:44 pm 
Offline

Joined: March 18th, 2008, 12:31 am
Posts: 63
Location: Barcelona, Catalonia
I am interested in opening a trayicon menu aswell. In my case to safely remove a flash memory. I'll keep an eye on this topic :)


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: February 18th, 2009, 9:27 pm 
Online
User avatar

Joined: December 26th, 2005, 4:40 pm
Posts: 8776
Tested and works

Code:
DetectHiddenWindows, On
TI := TrayIcons( "cfp.exe" )
StringSplit,TIV, TI, |
uID  := RegExReplace( TIV4, "uID: " )
Msg  := RegExReplace( TIV5, "MessageID: " )
hWnd := RegExReplace( TIV6, "hWnd: " )

PostMessage, Msg, uID,0x204,, ahk_id %hWnd% ; Right Click down
PostMessage, Msg, uID,0x205,, ahk_id %hWnd% ; Right Click Up


Dependency: You need Sean's TrayIcons()


Last edited by SKAN on February 21st, 2009, 1:06 pm, edited 1 time in total.

Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: February 18th, 2009, 10:07 pm 
Online
User avatar

Joined: December 26th, 2005, 4:40 pm
Posts: 8776
mai9 wrote:
I am interested in opening a trayicon menu aswell. In my case to safely remove a flash memory. I'll keep an eye on this topic :)


Tested in XP SP2 and Works!

Code:
#NoTrayIcon
DetectHiddenWindows, On
SafelyRemoveHardware()

SafelyRemoveHardware() {
 TrayInfo := TrayIcons()
 StringReplace, TrayInfo, TrayInfo, `n%A_Space%,, All
 Loop, Parse, TrayInfo, `n
  If ( SubStr(A_LoopField, -21) = "Safely Remove Hardware" ) {
    TI := A_LoopField
    Break
  }
 IfEqual,TI,,Return
 StringSplit,TIV, TI, |
 uID  := RegExReplace( TIV4, "uID: " )
 Msg  := RegExReplace( TIV5, "MessageID: " )
 hWnd := RegExReplace( TIV6, "hWnd: " )
 SendMessage, Msg, uID,0x201,, ahk_id %hWnd% ; Left Click down
 SendMessage, Msg, uID,0x202,, ahk_id %hWnd% ; Left Click Up
 WinWaitActive, Power Meter ahk_class SystemTray_Main ; Wait for Tray Menu
 Send {Down}{Enter} ; Select the First Drive menu Item
 Sleep 1000
 ControlClick,,ahk_class tooltips_class32 ; Dismiss Traytip: "Safe To Remove Hardware"
}


Dependency: You need Sean's TrayIcons()

_________________
URLGet - Internet Explorer based Downloader
StartEx - Portable Shortcut Link


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: February 18th, 2009, 11:35 pm 
Offline

Joined: March 18th, 2008, 12:31 am
Posts: 63
Location: Barcelona, Catalonia
Thanks SKAN. I tested it and it flickers that menu, but it doesn't stay and it seems like it clicks the first item.

I am using WinXP SP2 aswell.


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: February 19th, 2009, 6:43 am 
Online
User avatar

Joined: December 26th, 2005, 4:40 pm
Posts: 8776
Does the flash Drive gets removed or not? :roll:


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: February 20th, 2009, 4:24 pm 
Offline

Joined: February 7th, 2009, 11:28 pm
Posts: 384
Thank you for posting the examples SKAN. This may be a dumb question, but by "dependency" do you mean that anyone who uses your examples should "#include" the dependency too, or is there some other (better) way/command to call the linked function?

I'm trying your method out with Ghost-It, a tiny stand-alone system tray based utility for making windows translucent.

But I have 2 issues:

1. There's an unusually long delay (~5 sec) until the penultimate line of my code below is implemented. That is, Ghost-It's tray menu pops up as soon as I hit the hotkey (Ctrl+Win+RightClick), but AHK does not "SEND {DOWN 2}{ENTER}" to the menu for another 5 seconds; I can click 'Un-Ghost' or press down-down-enter to select it faster myself. What's wrong with the code?

Code:
#Include TrayIcon.ahk

^#LBUTTON:: ; Ctrl + Win + Left-Click to ghost
IfWinNotExist, ahk_class _GhostIt_Class
  {
    Run, "C:\Program Files\ghostit\GhostIt.exe"
    Sleep, 200
    TI := TrayIcons( "GhostIt.exe" )
    StringSplit,TIV, TI, |
    uID  := RegExReplace( TIV4, "uID: " )
    Msg  := RegExReplace( TIV5, "MessageID: " )
    hWnd := RegExReplace( TIV6, "hWnd: " )
  }
SendMessage, Msg, uID,0x203,, ahk_id %hWnd% ; Dbl Left-Click
Return

^#LBUTTON:: ; Ctrl + Win + Right-Click to un-ghost
SendMessage, Msg, uID,0x204,, ahk_id %hWnd% ; Right-Click down
SendMessage, Msg, uID,0x205,, ahk_id %hWnd% ; Right-Click Up
Send {DOWN 2}{ENTER} ; select Un-Ghost from pop-up menu
Return


2. TrayIcon.ahk popup: How do I dismiss it automatically? And for that matter, am I using TrayIcon.ahk correctly by including it at the start of the script, or is there a better way?

I mean, if I run TrayIcon first to look up the values for Ghost-It's uID (10001), Msg (1224) and hWnd (2490766), then all I need is the code below:

Code:
DetectHiddenWindows, On

^#LBUTTON::SendMessage, 1224, 10001,0x203,, ahk_id 2490766

^#RBUTTON::
SendMessage, 1224, 10001,0x204,, ahk_id 2490766
SendMessage, 1224, 10001,0x205,, ahk_id 2490766
Send {DOWN 2}{ENTER}
Return


The problem is that hWnd changes each time I restart Ghost-It, so that's why I've included TrayIcon.ahk in the script. But since it wasn't explicitly "included" in the other examples I've seen, I'm wondering if that's just something that's assumed to be obvious, or whether I missed something because I'm new to the forum and new to AHK?


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: February 20th, 2009, 10:10 pm 
Online
User avatar

Joined: December 26th, 2005, 4:40 pm
Posts: 8776
@pajenn

Quote:
by "dependency" do you mean that anyone who uses your examples should "#include" the dependency too, or is there some other (better) way/command to call the linked function?


You may copy/paste the TrayIcons() function into your script.

Quote:
1. There's an unusually long delay (~5 sec) until the penultimate line of my code below is implemented. That is, Ghost-It's tray menu pops up as soon as I hit the hotkey (Ctrl+Win+RightClick), but AHK does not "SEND {DOWN 2}{ENTER}" to the menu for another 5 seconds; I can click 'Un-Ghost' or press down-down-enter to select it faster myself. What's wrong with the code?


:shock: True!! I am unable to understand why this happens.. maybe Ghost-it is able to detect artificial clicks and slows down it!

Quote:
2. TrayIcon.ahk popup: How do I dismiss it automatically? And for that matter, am I using TrayIcon.ahk correctly by including it at the start of the script, or is there a better way?


In this case, you may use the #Include as the last line of your script to avoid the popup.

Quote:
I mean, if I run TrayIcon first to look up the values for Ghost-It's uID (10001), Msg (1224) and hWnd (2490766), then all I need is..


Good work! :D.. Use ahk_class instead of hard-coding the hwnd value, like in:

Code:
DetectHiddenWindows, On
IfWinNotExist, ahk_class _GhostIt_Class
  Run, "C:\Program Files\ghostit\GhostIt.exe"
Return

^#LButton::SendMessage, 1224, 10001,0x203,, ahk_class _GhostIt_Class

^#RBUTTON:: ; Ctrl + Win + Right-Click to un-ghost
 SendMessage, 1224, 10001,0x204,, ahk_class _GhostIt_Class
 SendMessage, 1224, 10001,0x205,, ahk_class _GhostIt_Class
 Send {DOWN 2}{ENTER}
Return

_________________
URLGet - Internet Explorer based Downloader
StartEx - Portable Shortcut Link


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: February 21st, 2009, 12:35 am 
Offline

Joined: February 7th, 2009, 11:28 pm
Posts: 384
thank you :D

_________________
Hardware: 1.8 GHz laptop with 4 GB ram, Windows XP/SP3
Software: Prevx, Privatefirewall, KeyScrambler.


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: February 21st, 2009, 10:17 am 
Offline

Joined: February 15th, 2009, 5:37 pm
Posts: 4
Sorry to reply late and thank you SKAN.

I tested the code and there's a popup, and in it the window for "cfp.exe" is shown, too. But all following commands are not executed anymore.

Update: I included the TrayIcon.ahk as you suggested last and it works!! :-)
Great code, now finding out how to select specific menu.

Code:
DetectHiddenWindows, On

TI := TrayIcons( "cfp.exe" )
StringSplit,TIV, TI, |
uID  := RegExReplace( TIV4, "uID: " )
Msg  := RegExReplace( TIV5, "MessageID: " )
hWnd := RegExReplace( TIV6, "hWnd: " )

MsgBox uID: %uID%, Msg: %Msg%, hWnd: %hWnd%

SendMessage, Msg, uID,0x204,, ahk_id %hWnd% ; Right Click down
SendMessage, Msg, uID,0x205,, ahk_id %hWnd% ; Right Click Up

SendMessage, Msg, uID,0x200,, Defense+ Security Level ahk_id %hWnd% ; Move mouse to this menu item?
; ABOVE command not working!
Sleep, 300
; SendMessage, Msg, uID,0x205,, ahk_id %hWnd% ; Right Click Up

MsgBox Now Defense+ should be disabled!

ExitApp


Now I am trying myself to find out how to disable the menu item.

Thanks again, AutoHotKey is really impressive :)


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: February 21st, 2009, 10:23 am 
Online
User avatar

Joined: December 26th, 2005, 4:40 pm
Posts: 8776
pajenn wrote:
thank you :D


No.. Thank you! I simplified Safely Remove Hardware

Code:
#NoTrayIcon
DetectHiddenWindows, On
Return

^F2::SafelyRemoveHardware()

SafelyRemoveHardware() {
 hWnd := WinExist( "Power Meter ahk_class SystemTray_Main" )
 SendMessage, 1226, 1226, 0x201,, ahk_id %hWnd% ; Left Click down
 SendMessage, 1226, 1226, 0x202,, ahk_id %hWnd% ; Left Click Up
 WinWaitActive, ahk_id %hWnd%,,1               ; Wait for SRH Tray left-click-Menu
 ControlSend,,{Down}{Enter},ahk_id %hWnd%      ; Select the first menu Item
 Send !{Esc}                                   ; Activate visible window
}


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: February 21st, 2009, 11:19 am 
Online
User avatar

Joined: December 26th, 2005, 4:40 pm
Posts: 8776
pajenn wrote:
1. There's an unusually long delay (~5 sec) until the penultimate line of my code below is implemented. That is, Ghost-It's tray menu pops up as soon as I hit the hotkey (Ctrl+Win+RightClick), but AHK does not "SEND {DOWN 2}{ENTER}" to the menu for another 5 seconds; I can click 'Un-Ghost' or press down-down-enter to select it faster myself. What's wrong with the code?


Oops... Sorry! SendMessage is waiting for a reply for 5 seconds!!!
Replace all SendMessage with PostMessage


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: February 21st, 2009, 11:32 am 
Online
User avatar

Joined: December 26th, 2005, 4:40 pm
Posts: 8776
Corvinian wrote:
I am trying myself to find out how to disable the menu item.



Code:
DetectHiddenWindows, On

^F5::  ; Defense+ Security Level: Safe Mode
ShowComodoTrayMenu()
Sleep 500
Send {Down 2}{Right}{Down 1}{Enter}
TrayTip, Defense+ Security Level, Safe Mode
Return

^F6::  ; Defense+ Security Level: Disabled
ShowComodoTrayMenu()
Sleep 500
Send {Down 2}{Right}{Down 4}{Enter}
TrayTip, Defense+ Security Level, Disabled
Return

ShowComodoTrayMenu() {
 WinGet, W, List, ahk_class Afx:00400000:0
 hWnd := W%W%
 PostMessage, 10045, 335,0x206,, ahk_id %hWnd% ; Right Click down
 PostMessage, 10045, 335,0x205,, ahk_id %hWnd% ; Right Click Up
}


Report this post
Top
 Profile  
Reply with quote  
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 51 posts ]  Go to page 1, 2, 3, 4  Next

All times are UTC [ DST ]


Who is online

Users browsing this forum: chaosad, Exabot [Bot], Google Feedfetcher, jrav and 20 guests


You can post new topics in this forum
You can reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Powered by phpBB® Forum Software © phpBB Group