CreatoX Posted September 22, 2011 Share Posted September 22, 2011 Hello, I wonder... is there an option in Autoit to choose an option for a program running in the system tray? For example: Right click on MSN Messenger and choose Log off (Afmelden in Dutch ) Hope this can be done. Link to comment Share on other sites More sharing options...
Moderators Melba23 Posted September 22, 2011 Moderators Share Posted September 22, 2011 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. expandcollapse popup#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 EndFuncYou 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 PPCC 1 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 columnsChooseFileFolder ---- Single and multiple selections from specified path treeview listingDate_Time_Convert -- Easily convert date/time formats, including the language usedExtMsgBox --------- A highly customisable replacement for MsgBoxGUIExtender -------- Extend and retract multiple sections within a GUIGUIFrame ---------- Subdivide GUIs into many adjustable framesGUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView itemsGUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeViewMarquee ----------- Scrolling tickertape GUIsNoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxesNotify ------------- Small notifications on the edge of the displayScrollbars ----------Automatically sized scrollbars with a single commandStringSize ---------- Automatically size controls to fit textToast -------------- Small GUIs which pop out of the notification area Link to comment Share on other sites More sharing options...
CreatoX Posted September 22, 2011 Author Share Posted September 22, 2011 Great!!! You save my day Link to comment Share on other sites More sharing options...
CreatoX Posted September 23, 2011 Author Share Posted September 23, 2011 Maybe now I'm going to far . But is there any way knowing which item is selected in the context menu? So for my example: 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 More sharing options...
Moderators Melba23 Posted September 23, 2011 Moderators Share Posted September 23, 2011 CreatoX,Would sir like fries with that? 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: expandcollapse popup#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 "" EndFuncThis 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 PoojaKrishna and PPCC 2 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 columnsChooseFileFolder ---- Single and multiple selections from specified path treeview listingDate_Time_Convert -- Easily convert date/time formats, including the language usedExtMsgBox --------- A highly customisable replacement for MsgBoxGUIExtender -------- Extend and retract multiple sections within a GUIGUIFrame ---------- Subdivide GUIs into many adjustable framesGUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView itemsGUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeViewMarquee ----------- Scrolling tickertape GUIsNoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxesNotify ------------- Small notifications on the edge of the displayScrollbars ----------Automatically sized scrollbars with a single commandStringSize ---------- Automatically size controls to fit textToast -------------- Small GUIs which pop out of the notification area Link to comment Share on other sites More sharing options...
bmw540 Posted November 22, 2011 Share Posted November 22, 2011 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 More sharing options...
Moderators Melba23 Posted November 22, 2011 Moderators Share Posted November 22, 2011 bmw540,Welcome to the AutoIt forum. 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. Post the reults of the Info Tool and we will see if we can get a suitable ID to use. M23 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 columnsChooseFileFolder ---- Single and multiple selections from specified path treeview listingDate_Time_Convert -- Easily convert date/time formats, including the language usedExtMsgBox --------- A highly customisable replacement for MsgBoxGUIExtender -------- Extend and retract multiple sections within a GUIGUIFrame ---------- Subdivide GUIs into many adjustable framesGUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView itemsGUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeViewMarquee ----------- Scrolling tickertape GUIsNoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxesNotify ------------- Small notifications on the edge of the displayScrollbars ----------Automatically sized scrollbars with a single commandStringSize ---------- Automatically size controls to fit textToast -------------- Small GUIs which pop out of the notification area Link to comment Share on other sites More sharing options...
bmw540 Posted November 22, 2011 Share Posted November 22, 2011 (edited) Thankyou, I find AutoIT and this forum very useful! 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_TrayWndPosition: 0, 760Size: 1280, 40Style: 0x96000000ExStyle: 0x00000088Handle: 0x00010064>>>> Control <<<<Class: ToolbarWindow32Instance: 1ClassnameNN: ToolbarWindow321Name:Advanced (Class): [CLASS:ToolbarWindow32; INSTANCE:1]ID: 1504Text: Meddelandefält för användarbefordranPosition: 868, 2Size: 318, 38ControlClick Coords: 123, 26Style: 0x56008B4DExStyle: 0x00000080Handle: 0x0001007E>>>> Mouse <<<<Position: 991, 788Cursor ID: 0Color: 0x8194AA>>>> StatusBar <<<<>>>> ToolsBar <<<<1: 12 Citrix Receiver2: 11 Check Point VPN-1 SecureClientConnected: NoSecurity Policy: No PolicySecurity Configuration: Not Verified3: 10 TeamViewer - 13213225564: 7 NetSupport ClientD830TEMP10.0.100.56:54055: 6 Dell Touchpad6: 4 Mobil bredbandsanslutningKlart7: 3 Säker borttagning av maskinvara och Mata ut media8: 2 Bluetooth-enheter9: 1 OfficeScan (Online)Antivirus Eng/Ptn: 9.500.1005/8.589.00DCS Eng/Ptn: 6.3.1015/116410: 0 Lös datorproblem: 2 viktiga meddelanden4 meddelanden totalt>>>> Visible Text <<<<12:42Meddelandefält för användarbefordranMeddelandefält för systembefordranTF_FloatingLangBar_WndTitleProgram som körsProgram som körs>>>> Hidden Text <<<< Edited November 23, 2011 by bmw540 Link to comment Share on other sites More sharing options...
Moderators Melba23 Posted November 22, 2011 Moderators Share Posted November 22, 2011 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. 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? M23 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 columnsChooseFileFolder ---- Single and multiple selections from specified path treeview listingDate_Time_Convert -- Easily convert date/time formats, including the language usedExtMsgBox --------- A highly customisable replacement for MsgBoxGUIExtender -------- Extend and retract multiple sections within a GUIGUIFrame ---------- Subdivide GUIs into many adjustable framesGUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView itemsGUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeViewMarquee ----------- Scrolling tickertape GUIsNoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxesNotify ------------- Small notifications on the edge of the displayScrollbars ----------Automatically sized scrollbars with a single commandStringSize ---------- Automatically size controls to fit textToast -------------- Small GUIs which pop out of the notification area Link to comment Share on other sites More sharing options...
Mat Posted November 22, 2011 Share Posted November 22, 2011 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. AutoIt Project Listing Link to comment Share on other sites More sharing options...
bmw540 Posted November 22, 2011 Share Posted November 22, 2011 Hi, here's the link to download the sw I'm trying to rightclick in tray and goto preferences: http://download.citrix.com.edgesuite.net/akdlm/6370/CitrixReceiverEnterprise.exe?__gda__=1321970404_b50205f15a14c0d58c46fe56f5166c34&__dlmgda__=1322056504_73fcd847b25abab46e127b8b63e5847e&fileExt=.exeMat, I tried winspector but I don't know how to use it. Link to comment Share on other sites More sharing options...
bmw540 Posted November 22, 2011 Share Posted November 22, 2011 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. expandcollapse popup#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 More sharing options...
Moderators Melba23 Posted November 22, 2011 Moderators Share Posted November 22, 2011 bmw540,Is there any way to hide whats happeningIf by that you mean hiding the mouse cursor while it does its thing, I am afraid not. 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. M23 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 columnsChooseFileFolder ---- Single and multiple selections from specified path treeview listingDate_Time_Convert -- Easily convert date/time formats, including the language usedExtMsgBox --------- A highly customisable replacement for MsgBoxGUIExtender -------- Extend and retract multiple sections within a GUIGUIFrame ---------- Subdivide GUIs into many adjustable framesGUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView itemsGUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeViewMarquee ----------- Scrolling tickertape GUIsNoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxesNotify ------------- Small notifications on the edge of the displayScrollbars ----------Automatically sized scrollbars with a single commandStringSize ---------- Automatically size controls to fit textToast -------------- Small GUIs which pop out of the notification area Link to comment Share on other sites More sharing options...
bmw540 Posted November 23, 2011 Share Posted November 23, 2011 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. this makes my life much easier. Great tip! bmw540 Link to comment Share on other sites More sharing options...
Moderators Melba23 Posted November 23, 2011 Moderators Share Posted November 23, 2011 bmw540, Glad I thought of it! M23 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 columnsChooseFileFolder ---- Single and multiple selections from specified path treeview listingDate_Time_Convert -- Easily convert date/time formats, including the language usedExtMsgBox --------- A highly customisable replacement for MsgBoxGUIExtender -------- Extend and retract multiple sections within a GUIGUIFrame ---------- Subdivide GUIs into many adjustable framesGUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView itemsGUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeViewMarquee ----------- Scrolling tickertape GUIsNoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxesNotify ------------- Small notifications on the edge of the displayScrollbars ----------Automatically sized scrollbars with a single commandStringSize ---------- Automatically size controls to fit textToast -------------- Small GUIs which pop out of the notification area Link to comment Share on other sites More sharing options...
EvgeniyEgiazarov Posted April 10, 2014 Share Posted April 10, 2014 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: expandcollapse popup#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 More sharing options...
ckovoor Posted September 10, 2014 Share Posted September 10, 2014 (edited) 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: expandcollapse popup#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 September 10, 2014 by ckovoor Link to comment Share on other sites More sharing options...
junkew Posted September 10, 2014 Share Posted September 10, 2014 example 3 gives directions FAQ 31 How to click some elements, FAQ 40 Test automation with AutoIt, Multithreading CLR .NET Powershell CMDLets Link to comment Share on other sites More sharing options...
ckovoor Posted September 10, 2014 Share Posted September 10, 2014 (edited) 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 September 10, 2014 by ckovoor Link to comment Share on other sites More sharing options...
junkew Posted September 10, 2014 Share Posted September 10, 2014 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 FAQ 31 How to click some elements, FAQ 40 Test automation with AutoIt, Multithreading CLR .NET Powershell CMDLets 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