Jump to content

Manipulate system tray program? (right click, choose option)


CreatoX
 Share

Recommended Posts

  • Moderators

CreatoX,

This code will right click on an icon containing a given text - I have found that Send("{UP}/{DOWN}{ENTER}") works well from then on if you add a Sleep(100) between multiple commands to allow them time to have effect. :graduated:

#Include <GuiToolBar.au3>

Global $hSysTray_Handle, $iSystray_ButtonNumber

Global $sToolTipTitle = "" ; <<<<<<<<<<<<<<<< Enter some tooltip text for the icon you want here

$iSystray_ButtonNumber = Get_Systray_Index($sToolTipTitle)

If $iSystray_ButtonNumber = 0 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 - 1
        If StringInStr(_GUICtrlToolbar_GetButtonText($hSysTray_Handle, $iSystray_ButtonNumber), $sToolTipTitle) <> 0 Then ExitLoop
    Next

    If $iSystray_ButtonNumber = $iSystray_ButCount Then
        Return 0 ; Not found
    Else
        Return $iSystray_ButtonNumber ; Found
    EndIf

EndFunc

You may find that there are accelerator keys within the menu and just Send("a") will work, although I see no sign of them in that image - worth a try though! ;)

M23

Public_Domain.png.2d871819fcb9957cf44f4514551a2935.png Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind

Open spoiler to see my UDFs:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Link to comment
Share on other sites

Maybe now I'm going to far :graduated: . But is there any way knowing which item is selected in the context menu?

So for my example:

Posted Image

Returning the value: "Afmelden"

Thanks again.

Btw. The script works very good! I just want to make it a bit more secure, knowing the selected item is indeed the item I am looking for.

Link to comment
Share on other sites

  • Moderators

CreatoX,

Would sir like fries with that? :graduated:

You can thank rover for this - all I have done is play around with his code to get a "simple" function to do what you want: ;)

#include <WindowsConstants.au3>
#include <GUIToolbar.au3>
#include <WinAPI.au3>
#Include <GuiMenu.au3>

Opt("WinTitleMatchMode", 2)

Global $hSysTray_Handle, $iSystray_ButtonNumber
Global $sToolTipTitle = ""  ; Add the text of your tray icon here <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<

$iSystray_ButtonNumber = Get_Systray_Index($sToolTipTitle)

If $iSystray_ButtonNumber = 0 Then
    MsgBox(16, "Error", "Is the App running?")
    Exit
Else
    Sleep(250)
    _GUICtrlToolbar_ClickButton($hSysTray_Handle, $iSystray_ButtonNumber, "right")
    Sleep(250)
    Send("{UP}") ; Move your cursor around on the menu here <<<<<<<<<<<<<<<<<<<<<<<<<<<
    ConsoleWrite(GetPopUpSelText() & @CRLF) ; This will read the currently selected item <<<<<<<<<<<<<<<<<<<<<<<<<<<<
EndIf

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 - 1
        If StringInStr(_GUICtrlToolbar_GetButtonText($hSysTray_Handle, $iSystray_ButtonNumber), $sToolTipTitle) <> 0 Then ExitLoop
    Next

    If $iSystray_ButtonNumber = $iSystray_ButCount Then
        Return 0 ; Not found
    Else
        Return $iSystray_ButtonNumber ; Found
    EndIf

EndFunc

Func GetPopUpSelText()

    Local $aPopUp_List = _WinAPI_EnumWindowsPopup()
    Local $hWnd = $aPopUp_List[1][0]
    Local $sClass = $aPopUp_List[1][1]
    If $sClass = "#32768" Then ; This is a "standard" Windows API popup menu
        $hMenu = _SendMessage($hWnd, $MN_GETHMENU, 0, 0)
        If _GUICtrlMenu_IsMenu($hMenu) Then
            $iCount = _GUICtrlMenu_GetItemCount($hMenu)
            For $j = 0 To $iCount - 1
                If _GUICtrlMenu_GetItemHighlighted($hMenu, $j) Then
                    Return _GUICtrlMenu_GetItemText($hMenu, $j)
                EndIf
            Next
        EndIf
    EndIf
    Return ""

EndFunc

This code only works on "standard" Windows API popup menus - one of the apps in my tray does not respond to this code as it uses owner-drawn elements which cannot be read. I hope your app is one of the well-behaved ones. :)

M23

Public_Domain.png.2d871819fcb9957cf44f4514551a2935.png Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind

Open spoiler to see my UDFs:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Link to comment
Share on other sites

  • 1 month later...

Hi,

I wonder if you could help me.

The above script works excellent on Windows 7 but it doesn't on Windows 7 SP1, I just get messaged "icon not found in system tray"

I have searched over and over and found this

Juvigy, Since the instance # for the 'Notification Area' can vary between O/S's, you might want to alter the following line:

$hSysTray_Handle = ControlGetHandle('[Class:Shell_TrayWnd]', '', '[Class:ToolbarWindow32;Instance:1]')

to search for '[CLASS:ToolbarWindow32;TEXT:Notification Area]' on anything pre-Windows 7, and for Windows 7:

"[CLASS:ToolbarWindow32;TEXT:User Promoted Notification Area]".

But i still cant get it to work, any ideas?

Best Regards

Simon

Link to comment
Share on other sites

  • Moderators

bmw540,

Welcome to the AutoIt forum. :D

What does the AutoIt Window Info Tool tell you about the systray on your system? It might well be that Win7 SP1 changes the descriptors again - MS have an annoying habit of doing this as you can see from the thread you linked to above. :rip:

Post the reults of the Info Tool and we will see if we can get a suitable ID to use. :oops:

M23

Public_Domain.png.2d871819fcb9957cf44f4514551a2935.png Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind

Open spoiler to see my UDFs:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Link to comment
Share on other sites

Thankyou, I find AutoIT and this forum very useful! :D

My bad, I got it to run.... but still verifying.

My intention was to uninstall citrix xenapp and install sw citrix receiver using the script aswell as modify settings on the software.

So I ran the script using "run as administrator" and so it did not work, but if I just run it as regular user, it works.

My guess is that the script isnt looking for the icon name in the current profile when using run as.

Is there any fix for that?

When running runas administrator AutoIt Window Info Tool and dragging the finder tool down to the notification area explorer.exe crashes and restarts.

>>>> Window <<<<

Title:

Class: Shell_TrayWnd

Position: 0, 760

Size: 1280, 40

Style: 0x96000000

ExStyle: 0x00000088

Handle: 0x00010064

>>>> Control <<<<

Class: ToolbarWindow32

Instance: 1

ClassnameNN: ToolbarWindow321

Name:

Advanced (Class): [CLASS:ToolbarWindow32; INSTANCE:1]

ID: 1504

Text: Meddelandefält för användarbefordran

Position: 868, 2

Size: 318, 38

ControlClick Coords: 123, 26

Style: 0x56008B4D

ExStyle: 0x00000080

Handle: 0x0001007E

>>>> Mouse <<<<

Position: 991, 788

Cursor ID: 0

Color: 0x8194AA

>>>> StatusBar <<<<

>>>> ToolsBar <<<<

1: 12 Citrix Receiver

2: 11 Check Point VPN-1 SecureClient

Connected: No

Security Policy: No Policy

Security Configuration: Not Verified

3: 10 TeamViewer - 1321322556

4: 7 NetSupport Client

D830TEMP

10.0.100.56:5405

5: 6 Dell Touchpad

6: 4 Mobil bredbandsanslutning

Klart

7: 3 Säker borttagning av maskinvara och Mata ut media

8: 2 Bluetooth-enheter

9: 1 OfficeScan (Online)

Antivirus Eng/Ptn: 9.500.1005/8.589.00

DCS Eng/Ptn: 6.3.1015/1164

10: 0 Lös datorproblem: 2 viktiga meddelanden

4 meddelanden totalt

>>>> Visible Text <<<<

12:42

Meddelandefält för användarbefordran

Meddelandefält för systembefordran

TF_FloatingLangBar_WndTitle

Program som körs

Program som körs

>>>> Hidden Text <<<<

Edited by bmw540
Link to comment
Share on other sites

  • Moderators

bmw540,

Seems that the [CLASS:ToolbarWindow32; INSTANCE:1] ID is still valid in Win7 - using text would have been a complete failure given the non-English OS you are using. :oops:

As to the problem with RunAs - how about starting the script as the normal user and so identifying the location of the relevant icon, then running a separate script as admin with the icon details passed as parameters to manipulate it? :D

M23

Public_Domain.png.2d871819fcb9957cf44f4514551a2935.png Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind

Open spoiler to see my UDFs:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Link to comment
Share on other sites

Although Melba has done a great job (as usual) at explaining how to automate clicking the tray icon, I think it should be mentioned that there are better alternatives. They don't always work, as it assumes that the controlling program is using the icon in a particular way, but it's a lot neater when it does work. I've answered a few questions on this (read from the 8th post down) and again

As said: It doesn't always work. It doesn't work with AutoIt tray menu items for example. But you might get lucky, in which case you end up with being able to click items without even bringing up menu items. It would also mean you never have to automate the taskbar, making your code a lot more future proof.

If Melba's method works for you then by all means stay with it. This post was just to demonstrate that there are alternatives.

Link to comment
Share on other sites

Ok, so this is what im running and it works on a x86 W7SP1 I will test on a x64 tomorrow.

Is there any way to hide whats happening? I have been looking for switches to the created exe of the compiled script below.

#include <WindowsConstants.au3>
#include <GUIToolbar.au3>
#include <WinAPI.au3>
#Include <GuiMenu.au3>
; PNA uninstalled and Receiver installed
; Start showing Notification Area Icons
Send( '^{ESC}' ) ; Presses the StartMenu button
Sleep(250)
Send( '^{ESC}' ) ; Presses the StartMenu button
Sleep(250)
Send("{APPSKEY}") ; RightClicks the StartMenu button
Sleep(250)
Send("{UP}") ; Moves to Properties of the StartMenu button
Sleep(250)
Send("{ENTER}") ; Presses Enter on the Properties of the StartMenu button
Sleep(250)
Send("{TAB}{TAB}{TAB}{TAB}{TAB}{ENTER}") ; Tabs down to "Anpassa" and presses Enter
Sleep(10000) ; Wait for the properties window to appear
Send("+{TAB}") ; Sends Shift-TAB to highlight "Visa alltid alla ikoner och meddelanden i Aktivitetsfältet"
Sleep(250)
Send("{SPACE}") ; Sends space to select the above
Sleep(250)
Send("{TAB}") ; Sends TAB to higlight "OK"
Sleep(250)
Send("{ENTER}") ; Sends ENTER to save settings
Sleep(250)
Send("{TAB}{TAB}{TAB}{ENTER}") ; Tabs down to "OK or Avbryt" to exit
; Now all Notification Area icons shall be visible
Sleep(500)
; Now the customize Citrix receiver part starts
Opt("WinTitleMatchMode", 2)
Global $hSysTray_Handle, $iSystray_ButtonNumber
Global $sToolTipTitle = "Citrix Receiver"  ; Add the text of your tray icon here <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
$iSystray_ButtonNumber = Get_Systray_Index($sToolTipTitle)
If $iSystray_ButtonNumber = 0 Then
    MsgBox(16, "Error", "Is the App running?")
    Exit
Else
    Sleep(500)
    _GUICtrlToolbar_ClickButton($hSysTray_Handle, $iSystray_ButtonNumber, "right")  ; Rightclicks Citrix Receiver
    Sleep(500)
    Send("{DOWN}{ENTER}") ; Walk down to "Preferences" and press enter
Sleep(2000) ; Wait 1 sec to let it load Preferences
Send("{UP}")  ; Jump up to "User Settings"
Sleep(250)
Send("{TAB}") ; Jump to "Show advanced Receiver menu items"
Sleep(250)
Send("{SPACE}") ; Sends SPACE to select the above
Sleep(250)
Send("+{TAB}"); Sends Shift-TAB to jump back to "User Settings"
Sleep(250)
Send("{DOWN}"); Sends DOWN to move to "Plug-in status"
Sleep(250)
Send("{TAB}") ; Sends TAB to move to "Online Plug-in......."
Sleep(250)
Send("{APPSKEY}"); RightClicks the above
Sleep(250)
Send("{UP}"); Sends UP to jump to "Options"
Sleep(250)
Send("{ENTER}"); Sends ENTER on the above
Sleep(250)
Send("+{TAB}"); Sends Shift-TAB to jump back to "Server Options"
Sleep(250)
Send("{DOWN}"); Sends DOWN to jump to "Application Display"
Sleep(250)
Send("{TAB}") ; Sends TAB to move to "Show applications in Start Menu"
Sleep(250)

Send("{TAB}"); Sends TAB to move to field "Additional submenu"
Sleep(250)
Send("Citrix Program"); Enters the desired text in the field above
Sleep(1500)
Send("{ENTER}"); Closes the window
Sleep(250)
Send("{TAB}"); Jumps to "OK"
Sleep(250)
Send("{ENTER}"); Sends ENTER to exit above
; Reciever part is finished

; Now hiding all Notification Area icons starts
Send( '^{ESC}' ) ; Presses the StartMenu button
Sleep(250)
Send( '^{ESC}' ) ; Presses the StartMenu button
Sleep(250)
Send("{APPSKEY}") ; RightClicks the StartMenu button
Sleep(250)
Send("{UP}") ; Moves to Properties of the StartMenu button
Sleep(250)
Send("{ENTER}") ; Presses Enter on the Properties of the StartMenu button
Sleep(250)
Send("{TAB}{TAB}{TAB}{TAB}{TAB}{ENTER}") ; Tabs down to "Anpassa" and presses Enter
Sleep(10000) ; Wait for the properties window to appear
Send("+{TAB}"); Sends Shift-TAB to highlight "Visa alltid alla ikoner och meddelanden i Aktivitetsfältet"
Sleep(250)
Send("{SPACE}") ; Sends space to select the above
Sleep(250)
Send("{TAB}") ; Sends TAB to higlight "OK"
Sleep(250)
Send("{ENTER}") ; Sends ENTER to save settings
Sleep(250)
Send("{TAB}{TAB}{TAB}{ENTER}") ; Tabs down to "OK or Avbryt" to exit
Sleep(250)
; Now the Notification Area icons shall be as before the script run

    ConsoleWrite(GetPopUpSelText() & @CRLF) ; This will read the currently selected item <<<<<<<<<<<<<<<<<<<<<<<<<<<<
EndIf
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 - 1
        If StringInStr(_GUICtrlToolbar_GetButtonText($hSysTray_Handle, $iSystray_ButtonNumber), $sToolTipTitle) <> 0 Then ExitLoop
    Next
    If $iSystray_ButtonNumber = $iSystray_ButCount Then
        Return 0 ; Not found
    Else
        Return $iSystray_ButtonNumber ; Found
    EndIf
EndFunc
Func GetPopUpSelText()
    Local $aPopUp_List = _WinAPI_EnumWindowsPopup()
    Local $hWnd = $aPopUp_List[1][0]
    Local $sClass = $aPopUp_List[1][1]
    If $sClass = "#32768" Then ; This is a "standard" Windows API popup menu
        $hMenu = _SendMessage($hWnd, $MN_GETHMENU, 0, 0)
        If _GUICtrlMenu_IsMenu($hMenu) Then
            $iCount = _GUICtrlMenu_GetItemCount($hMenu)
            For $j = 0 To $iCount - 1
                If _GUICtrlMenu_GetItemHighlighted($hMenu, $j) Then
                    Return _GUICtrlMenu_GetItemText($hMenu, $j)
                EndIf
            Next
        EndIf
    EndIf
    Return ""
EndFunc
func rightclick()
    MouseClick("right")
endfunc
Link to comment
Share on other sites

  • Moderators

bmw540,

Is there any way to hide whats happening

If by that you mean hiding the mouse cursor while it does its thing, I am afraid not. :D

One thing I have just thought of - does the menu have accelerator keys? By that I mean that you can press a certain key to operate a certain menu item - usually an "accelerated" menu item has an underlined letter. It might make the process a little cleaner - but not all menus have them, alas. :oops:

M23

Public_Domain.png.2d871819fcb9957cf44f4514551a2935.png Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind

Open spoiler to see my UDFs:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Link to comment
Share on other sites

M23,

Yes, when the menu is open I can press P and it then opens Preferences and when preferences has loaded pressing U takes me to User settings, pressing S checks the box "Show advanced Receiver menu items" this is much more secure as the first menu has one more option when "Show advanced Receiver menu items" has been selected. :D this makes my life much easier. Great tip!

bmw540

Link to comment
Share on other sites

  • Moderators

bmw540,

Glad I thought of it! :D

M23

Public_Domain.png.2d871819fcb9957cf44f4514551a2935.png Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind

Open spoiler to see my UDFs:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Link to comment
Share on other sites

  • 2 years later...

Some additions to Melba23's code that take into account overflow section of system tray and correct bug with indexing 0th item on the toolbar:

#Include <GuiToolBar.au3>
#include <GuiButton.au3>

Global $hSysTray_Handle, $iSystray_ButtonNumber

Global $sToolTipTitle = "Pointing" ; <<<<<<<<<<<<<<<< Enter some tooltip text for the icon you want here

$iSystray_ButtonNumber = Get_Systray_Index($sToolTipTitle)

If $iSystray_ButtonNumber = -1 Then
    MsgBox(16, "Error", "Icon not found in system tray")
    Exit
Else
    Sleep(500)
    ; right click and select first menu item
    _GUICtrlToolbar_ClickButton($hSysTray_Handle, $iSystray_ButtonNumber, "right")
    Send("{DOWN}{ENTER}")
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
        ; check overflow section of systray
         Return Get_OverflowSystray_Index($sToolTipTitle)
    EndIf

    ; Look for wanted tooltip
    For $iSystray_ButtonNumber = 0 To $iSystray_ButCount - 1
        If StringInStr(_GUICtrlToolbar_GetButtonText($hSysTray_Handle, $iSystray_ButtonNumber), $sToolTipTitle) <> 0 Then ExitLoop
    Next

    If $iSystray_ButtonNumber = $iSystray_ButCount Then
        Return Get_OverflowSystray_Index($sToolTipTitle)
     Else
        Return $iSystray_ButtonNumber ; Found
    EndIf

EndFunc


Func Get_OverflowSystray_Index($sToolTipTitle)

   $hSysTray_Handle = ControlGetHandle('[Class:NotifyIconOverflowWindow]', '', '[Class:ToolbarWindow32;Instance:1]')
   $iSystray_ButCount = _GUICtrlToolbar_ButtonCount($hSysTray_Handle)
   If $iSystray_ButCount = 0 Then
      MsgBox(16, "Error", "No items found in system tray")
      Exit
   EndIf

   For $iSystray_ButtonNumber = 0 To $iSystray_ButCount - 1
     If StringInStr(_GUICtrlToolbar_GetButtonText($hSysTray_Handle, $iSystray_ButtonNumber), $sToolTipTitle) <> 0 Then ExitLoop
   Next
   If $iSystray_ButtonNumber < $iSystray_ButCount Then
      $hSysTray_OverflowButton = ControlGetHandle('[Class:Shell_TrayWnd]', '', '[CLASS:Button; INSTANCE:1]')
      _GUICtrlButton_Click($hSysTray_OverflowButton)
      Return $iSystray_ButtonNumber ; Found
   Else
      Return -1
   EndIf

EndFunc
Link to comment
Share on other sites

  • 4 months later...

Hi,

I am using a modified version of this script to toggle the enable/disable Input Director macro switch that is available on the right-click menu drawn up when you access the Input Director tray icon (Input Director is a great program for handling networked pc's with a single keyboard and mouse). Thank you Melba23 for the fantastic script and EvgeniyEgiazarov for your additions/corrections:

#Region ;**** Directives created by AutoIt3Wrapper_GUI ****
#AutoIt3Wrapper_Compile_Both=y
#AutoIt3Wrapper_UseX64=y
#EndRegion ;**** Directives created by AutoIt3Wrapper_GUI ****
#include <Constants.au3>
;
; AutoIt Version: 3.0
; Language:       English
; Platform:       Win9x/NT
; Author:         Melba23 (modified by Chakko Kovoor)
;
; Script Function:
;   toggles enable/disable macros (switch)on Input Director menu brought up when you right-click on its tray icon, with confirmation of action
;

#include <WindowsConstants.au3>
#include <GUIToolbar.au3>
#include <WinAPI.au3>
#Include <GuiMenu.au3>
#include <GuiButton.au3>

Opt("WinTitleMatchMode", 2)
Global $hSysTray_Handle, $iSystray_ButtonNumber, $sItemName

Global $sToolTipTitle = "Input Director (Master)" ; <<<<<<<<<<<<<<<< Enter some tooltip text for the icon you want here

$iSystray_ButtonNumber = Get_Systray_Index($sToolTipTitle)

If $iSystray_ButtonNumber = -1 Then
    MsgBox(16, "Error", "Icon not found in system tray")
    Exit
Else
    Sleep(250)
    ; right click and select fourth menu item (up)
    _GUICtrlToolbar_ClickButton($hSysTray_Handle, $iSystray_ButtonNumber, "right")
    Sleep(1000)
    Send("{UP 4}")
    $sItemName = GetPopUpSelText() ; This will read the currently selected item <<<<<<<<<<<<<<<<<<<<<<<<<<<<
    Send("{ENTER}")
    If $sItemName = "Enable Macros" Then
        SplashTextOn ( "", "Macros ENABLED" , 160 , 40, -1, -1, 1,"",10, 600 )
        Sleep (3000)
        SplashOff ()
     Elseif $sItemName = "Disable Macros" Then
        SplashTextOn ( "", "Macros DISABLED" , 160 , 40, -1, -1, 1,"",10, 600 )
        Sleep (3000)
        SplashOff ()
     Else
        SplashTextOn ( "", "Option Not Found!" , 160 , 40, -1, -1, 1,"",10, 600 )
        Sleep (3000)
        SplashOff ()
    EndIf
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
        ; check overflow section of systray
         Return Get_OverflowSystray_Index($sToolTipTitle)
    EndIf

    ; Look for wanted tooltip
    For $iSystray_ButtonNumber = 0 To $iSystray_ButCount - 1
        If StringInStr(_GUICtrlToolbar_GetButtonText($hSysTray_Handle, $iSystray_ButtonNumber), $sToolTipTitle) <> 0 Then ExitLoop
    Next

    If $iSystray_ButtonNumber = $iSystray_ButCount Then
        Return Get_OverflowSystray_Index($sToolTipTitle)
     Else
        Return $iSystray_ButtonNumber ; Found
    EndIf

EndFunc


Func Get_OverflowSystray_Index($sToolTipTitle)

   $hSysTray_Handle = ControlGetHandle('[Class:NotifyIconOverflowWindow]', '', '[Class:ToolbarWindow32;Instance:1]')
   $iSystray_ButCount = _GUICtrlToolbar_ButtonCount($hSysTray_Handle)
   If $iSystray_ButCount = 0 Then
      MsgBox(16, "Error", "No items found in system tray")
      Exit
   EndIf

   For $iSystray_ButtonNumber = 0 To $iSystray_ButCount - 1
     If StringInStr(_GUICtrlToolbar_GetButtonText($hSysTray_Handle, $iSystray_ButtonNumber), $sToolTipTitle) <> 0 Then ExitLoop
   Next
   If $iSystray_ButtonNumber < $iSystray_ButCount Then
      $hSysTray_OverflowButton = ControlGetHandle('[Class:Shell_TrayWnd]', '', '[CLASS:Button; INSTANCE:1]')
      _GUICtrlButton_Click($hSysTray_OverflowButton)
      Return $iSystray_ButtonNumber ; Found
   Else
      Return -1
   EndIf

EndFunc


Func GetPopUpSelText()

    Local $aPopUp_List = _WinAPI_EnumWindowsPopup()
    Local $hWnd = $aPopUp_List[1][0]
    Local $sClass = $aPopUp_List[1][1]
    If $sClass = "#32768" Then ; This is a "standard" Windows API popup menu
        $hMenu = _SendMessage($hWnd, $MN_GETHMENU, 0, 0)
        If _GUICtrlMenu_IsMenu($hMenu) Then
            $iCount = _GUICtrlMenu_GetItemCount($hMenu)
            For $j = 0 To $iCount - 1
                If _GUICtrlMenu_GetItemHighlighted($hMenu, $j) Then
                    Return _GUICtrlMenu_GetItemText($hMenu, $j)
                EndIf
            Next
        EndIf
    EndIf
    Return ""

EndFunc

Now, I would like to introduce a hotkey option to this script, so that once the script is run by clicking on its icon, it gets loaded to the pc memory/tray, and can thereafter be run again repeatedly with a hotkey. I tried to introduce the line:

HotKeySet ("{F11}")

at the beginning of the script, while also removing the Exit at the end of the code, but it did not work. The script ran, but pressing the hotkey evoked no response. Would anyone be able to help me with this?

Thanks,

Chakko.

Edited by ckovoor
Link to comment
Share on other sites

Hi junkew,

Thank you so much for taking an interest in this. I should have clarified that I am a novice programmer and new to autoit, so I am unable to see how your example would help me introduce a hotkey into my script. Perhaps you would be able to expand on the method?

Thank you so much for your time.

Regards,

Chakko.

Edited by ckovoor
Link to comment
Share on other sites

https://www.autoitscript.com/autoit3/docs/functions/HotKeySet.htm

you need to set the function to call

My answer was more on handling the tray area. IUIAutomation reveals a little more information than AutoIT out of the box but the concepts are a little harder to grasp

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...