rasim Posted February 1, 2008 Share Posted February 1, 2008 (edited) Hi! Probably many peoples face a problem, when there was need to click on item in Windows system tray. I found (probably) a little solution for this problem. expandcollapse popup#NoTrayIcon #Include <GuiToolBar.au3> _SysTray_ClickItem("AIMP2", "right", 1) If @error Then MsgBox(48, "Failure", "Required item not found") ;=========# _SysTray_ClickItem #====================================================== ; ;Function Name: _SysTray_ClickItem() ;Description: Click on item in Windows system tray by any substring in the title ;Parameters: $iTitle - The title of the item in Windows system tray (you can see the title of the item when mouse cursor hovered on item). ; $iButton - [optional] The button to click, "left" or "right". Default is the left button. ; $iClick - [optional] The number of times to click the mouse. Default is 1 ; $sMove = [optional] True = Mouse will be moved, False (default) = Mouse will not be moved ; $iSpeed = [optional] Mouse movement speed ;Return Value(s): Success - Returns 1 ; Failure - Returns 0 and sets @error to 1 if required item not found ;Requirement(s): AutoIt 3.2.10.0 and above ;Autor(s): R.Gilman (a.k.a rasim); Siao (Thanks for idea) ; ;==================================================================================== Func _SysTray_ClickItem($iTitle, $iButton = "left", $iClick = 1, $sMove = False, $iSpeed = 1) Local $hToolbar, $iButCount, $aRect, $hButton, $cID, $i $hToolbar = ControlGetHandle("[Class:Shell_TrayWnd]", "", "[Class:ToolbarWindow32;Instance:1]") If @error Then Return SetError(1, 0, 0) EndIf $iButCount = _GUICtrlToolbar_ButtonCount($hToolbar) If $iButCount = 0 Then Return SetError(1, 0, 0) EndIf $hButton = ControlGetHandle("[Class:Shell_TrayWnd]", "", "Button2") If $hButton <> "" Then ControlClick("[Class:Shell_TrayWnd]", "", "Button2") For $i = 0 To $iButCount - 1 $cID = _GUICtrlToolbar_IndexToCommand($hToolBar, $i) If StringInStr(_GUICtrlToolbar_GetButtonText($hToolBar, $cID), $iTitle) Then _GUICtrlToolbar_ClickButton($hToolbar, $cID, $iButton, $sMove, $iClick, $iSpeed) Return 1 EndIf Next Return SetError(1, 0, 0) EndFunc Edited August 19, 2008 by rasim Link to comment Share on other sites More sharing options...
ToyleY Posted February 2, 2008 Share Posted February 2, 2008 I just get a box saying "Fail", "Required item not found" Running Window XP, AutoIt 3.2.10.0 What is it supposed to do - I can't follow the code? Link to comment Share on other sites More sharing options...
xertroyt Posted February 9, 2008 Share Posted February 9, 2008 Rasim, I notice that you never use the variable $cID. Should calls like _GUICtrlToolbar_GetButtonText($hToolBar, $i) be using $i or $cID ? Also, it doesn't work for me. I put a MsgBox inside the loop to each at each value of _GUICtrlToolbar_GetButtonText($hToolBar, $i), and it seems to be missing some of them. ToyleY For $i = 0 To $iButCount - 1 $cID = _GUICtrlToolbar_IndexToCommand($hToolBar, $i) If StringInStr(_GUICtrlToolbar_GetButtonText($hToolBar, $i), $iTitle) Then $aRect = _GUICtrlToolbar_GetButtonRect($hToolBar, $i) ControlClick("[Class:Shell_TrayWnd]", "", "ToolbarWindow321", $iButton, $iClick, $aRect[0], 5) $aRect = 0 Return 1 EndIf Next MsgBox(48, "Fail", "Required item not found") EndFunc Link to comment Share on other sites More sharing options...
Greenhorn Posted February 9, 2008 Share Posted February 9, 2008 Moin rasim,I tested the script and it works fine until today.Great work, my friend !Thanx for sharing it here !GreetzGreenhorn Link to comment Share on other sites More sharing options...
tig8drag Posted August 5, 2008 Share Posted August 5, 2008 that's very good man !! thanks ... but haw can I access to other options in a system tray icon ?? (right click then left click in the choice) ?? tester under construction ... please wait Link to comment Share on other sites More sharing options...
wraithdu Posted August 5, 2008 Share Posted August 5, 2008 Nice script. Few things - It doesn't work for the special notification icon in Vista, ie volume, network, clock, power. It doesn't work right if you auto-hide the systray icons. You have to give the little button a click to show all icons, then it works perfectly. Good job! Link to comment Share on other sites More sharing options...
rasim Posted August 6, 2008 Author Share Posted August 6, 2008 tig8dragbut haw can I access to other options in a system tray icon ??This function don`t works with the context menu of any applications, if you need this, that just modify this example wraithduIt doesn't work for the special notification icon in Vista, ie volume, network, clock, power.In Windows XP this function works fine.It doesn't work right if you auto-hide the systray icons. You have to give the little button a click to show all icons, then it works perfectly.Fixed, updated first post. Link to comment Share on other sites More sharing options...
wraithdu Posted August 6, 2008 Share Posted August 6, 2008 (edited) In Windows XP this function works fine.I know that, that's why I stated it doesn't work in Vista. This is because in Vista those four notification icons are part of a different toolbar window, INSTANCE:2. I supposed you could add a check for @OSVersion == "WIN_VISTA" and if so, also loop through ToolbarWindow322.I'm not on an XP machine to check, but under Vista the systray button is Button1 (INSTANCE:1). And you might also want to add a Sleep(250) or so after the click on the button to show all the icons. It takes a second for the thing to expand all the way.Keep up the good work! Edited August 6, 2008 by wraithdu Link to comment Share on other sites More sharing options...
Rob08 Posted August 17, 2008 Share Posted August 17, 2008 Thanks! That's exactly what I was looking for. But could you explain it? I have little knowledge about functions. I don't know what your code does. For example, this line: $iTitle, $iButton = "left", $iClick = 2) Local $hToolbar, $iButCount, $aRect, $hButton, $cID, $i. Link to comment Share on other sites More sharing options...
amuskie Posted August 18, 2008 Share Posted August 18, 2008 Very cool! Link to comment Share on other sites More sharing options...
amuskie Posted August 19, 2008 Share Posted August 19, 2008 Rasim, After I did more test, I've found some issues while try to set the Right Click to the SuperAntiSpyware tray icon Here are the those different results: 1. no problem 2. it only bring up the task bar right click menu 3. it bring up both menu of SuperAntiSpyware and task bar fyi, they all three got the @Error 0 and the Left Click seems doing fine. Link to comment Share on other sites More sharing options...
rasim Posted August 19, 2008 Author Share Posted August 19, 2008 amuskieFixed! Updated first post! Link to comment Share on other sites More sharing options...
amuskie Posted August 19, 2008 Share Posted August 19, 2008 rasim, Thanks for the wonderful job and now is working fine! Link to comment Share on other sites More sharing options...
Hoox Posted August 22, 2008 Share Posted August 22, 2008 Would there be any way to click a systray icon that has no label when hovering mouse? Can I insert "blank"? It's the only icon in systray that don't have a label. Link to comment Share on other sites More sharing options...
ajones Posted August 25, 2008 Share Posted August 25, 2008 Rasim, I'll repeat a question I already asked you before: When the taskbar is unlocked and dragged down out of sight, then the system tray is not visible right? In this case, your script gives NO error but FAILS to work correctly! So in order for the script to work correctly and click the system tray icon, the taskbar should be visible. My question is, is there some way to make the script work even if the taskbar is not visible on-screen? Thanks for the script! - Andrew Link to comment Share on other sites More sharing options...
rivets Posted October 3, 2008 Share Posted October 3, 2008 I have tried this code under XP and it locates the button I want fine but I only get the taskbar menu not the tray item right-click menu. Any more suggestions? Link to comment Share on other sites More sharing options...
usmiv4o Posted November 12, 2008 Share Posted November 12, 2008 (edited) I have tried this code under XP and it locates the button I want fine but I only get the taskbar menu not the tray item right-click menu. Any more suggestions?I will suggest an Idea1. Desktop image capture2. search down right for you pattern3. go therep.s. for some programs it works with up and down arrow, but not for all Edited November 12, 2008 by usmiv4o I have nothing to be proud: I am Bulgarian :~But there is no better place than 127.0.0.1Tutorial for newbies Link to comment Share on other sites More sharing options...
zone97 Posted November 28, 2008 Share Posted November 28, 2008 this is a great script, how can you make it trigger on an event. I have a need where my bluetooth icon needs to be clicked to bring a screen to the front, but its the icon itself that "moves" when the hidden windows needs to be accessed. Spoiler WinSizer 2.1 (01/04/2017) - Download - [ Windows Layout Manager ]Folder+Program (12/23/2016) - Download - [ USB Shortcut Creator ] Link to comment Share on other sites More sharing options...
rasim Posted November 29, 2008 Author Share Posted November 29, 2008 how can you make it trigger on an eventWhat the event? When the required icon appearing on taskbar? Link to comment Share on other sites More sharing options...
zone97 Posted November 29, 2008 Share Posted November 29, 2008 Well what happens is the bluetooth icon moves from "some" position in the tray to the far left. it also produces a "ballon tip" but I have ballon tips removed. when you single left click on the bluetooth icon it will produce the window needing attention. Spoiler WinSizer 2.1 (01/04/2017) - Download - [ Windows Layout Manager ]Folder+Program (12/23/2016) - Download - [ USB Shortcut Creator ] Link to comment Share on other sites More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now