Jump to content

Right Click on Tray Icon


Recommended Posts

Hello AutoIt forums!

 

I was hoping you might be able to help me out with a predicament here.  I have spent a few days researching this on the forums and elsewhere, but don't seem to be able to find any specific answers for my needs.  It could very well be that I am drastically overlooking something simple.  Here goes.

 

I am trying to have AutoIt right click on a tray icon and bring up the menu.  Below is the information I get from my taskbar tray area:

>>>> Window <<<<
Title:    
Class:    Shell_TrayWnd
Position:    0, 1040
Size:    1920, 40
Style:    0x96000000
ExStyle:    0x00000088
Handle:    0x00010316

>>>> Control <<<<
Class:    ToolbarWindow32
Instance:    3
ClassnameNN:    ToolbarWindow323
Name:    
Advanced (Class):    [CLASS:ToolbarWindow32; INSTANCE:3]
ID:    1504
Text:    User Promoted Notification Area
Position:    1683, 0
Size:    120, 40
ControlClick Coords:    27, 15
Style:    0x56008B4D
ExStyle:    0x00000080
Handle:    0x00010340

>>>> Mouse <<<<
Position:    1710, 15
Cursor ID:    0
Color:    0x08090A

>>>> StatusBar <<<<

>>>> ToolsBar <<<<
1:    2    Ninite Updater - Last update check: 1/28/2020 1:43 PM
Updates available: Glary, Notepad++
2:    3    OneDrive - Oregon POS
Up to date
3:    4    Dropbox 89.4.278
Waiting to be linked to a Dropbox account...
4:    1    Network
Internet access
5:    0    Speakers: 14%

>>>> Visible Text <<<<
Start
Type here to search
Type here to search
Task View
Running applications
Running applications
HPSA_TASKBAR
System Promoted Notification Area
User Promoted Notification Area
System Clock, 3:16 PM, ‎1/‎28/‎2020
Action Center


>>>> Hidden Text <<<<
Type here to search
Tray Input Indicator
 

I understand that I can use ControlClick to right click on things, but I can't for the life of me figure out how to get it to right click on a specific icon in the tray area.  Is there a way to pass the codes under the "ToolsBar" section to ControlClick...?

Also, I would just use the coordinates on the screen, but I need this to work across different computer environments that may not always be the same.  This is why I need to work with the specific ID of the tray icon.

Anyone have any idea where I can go with this??  I've tried countless different combinations of ControlClick and passing different information through it from the window info tool...but I just can't seem to get it to do a dang thing.

Link to comment
Share on other sites

Link to comment
Share on other sites

When I run that, it opens up the hidden task bar, which is great!  At least I know it's clicking over there now.

Now if I wanted it to right click on entry 1 in the ToolsBar section of the info, what info do I need to pass to this thing?

Link to comment
Share on other sites

Oh and I now see that you're using 1502, which is the ID of the hidden taskbar button, so that's why that's happening.  So if I were to use 1504, how could I narrow that down to click on entry 1 within 1504?  This is the part that confuses me....

Link to comment
Share on other sites

Hi maloysius :)
A script found at this link could be helpful, as long as the system tray icon you want to click on got a tooltip (which is common in the notification area). I paste the script below, amended with a few added lines to make it work in case the icon is hidden :

#Include <GuiToolBar.au3>
#NoTrayIcon

Global $hSysTray_Handle, $iSystray_ButtonNumber

; Global $sToolTipTitle = "Microsoft Office Outlook" ; <<<<<<<<<<<<<<<< Enter some tooltip text for the icon you want here
Global $sToolTipTitle = "Intel(R)" ; <<<<<<<<<<<<<<<< you can enter prefix of your tooltip, no need to enter it all

;~ WinActivate('[Class:Shell_TrayWnd]') ; if taskbar is Autohide

$iSystray_ButtonNumber = Get_Systray_Index($sToolTipTitle)

If $iSystray_ButtonNumber = -1 Then
    MsgBox(16, "Error", "Icon not found in system tray")
    Exit
Else
    Sleep(500)
    _GUICtrlToolbar_ClickButton($hSysTray_Handle, $iSystray_ButtonNumber, "right")
EndIf

Exit

Func Get_Systray_Index($sToolTipTitle)

    ; Find systray handle
    $hSysTray_Handle = ControlGetHandle('[Class:Shell_TrayWnd]', '', '[Class:ToolbarWindow32;Instance:1]')
    If @error Then
        MsgBox(16, "Error", "System tray not found")
        Exit
    EndIf

    ; Get systray item count
    Local $iSystray_ButCount = _GUICtrlToolbar_ButtonCount($hSysTray_Handle)
    If $iSystray_ButCount = 0 Then
        MsgBox(16, "Error", "No items found in system tray")
        Exit
    EndIf

    ; Look for wanted tooltip
    For $iSystray_ButtonNumber = 0 To $iSystray_ButCount
        If StringInStr(_GUICtrlToolbar_GetButtonText($hSysTray_Handle, $iSystray_ButtonNumber), $sToolTipTitle) <> 0 Then
            ; MsgBox(0,$iSystray_ButCount,$iSystray_ButtonNumber) ; uncomment if you need info

            ; 2 lines added in case the icon is hidden (thanks Nine) <=======================
            Local $hWnd = WinGetHandle ('[Class:Shell_TrayWnd]')
            ControlClick($hWnd, '', 1502)

            ControlClick($hSysTray_Handle, "", $iSystray_ButtonNumber, "right") ; <==========

            Return $iSystray_ButtonNumber ; Found
        EndIf
    Next
    Return -1 ; Not found

EndFunc

Also, here is an interesting link to choose which items are shown in the notification area, from earlier Windows versions to Windows 10. Good luck :)

Edited by pixelsearch
Link to comment
Share on other sites

  • 2 months later...
On 2/3/2020 at 9:12 AM, pixelsearch said:

...amended with a few added lines to make it work in case the icon is hidden...

Thanks for pointing this code out, Pixelsearch! Perfect for my need to control the system tray. I just added send("{up"}{enter}") to select from the resulting popup although I'm sure there's a better way.

However, your code to make it work when hidden doesn't work for me. It just says "Icon not found..." on my Win7/64 machine.

Link to comment
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
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...