Jump to content

check whether the mouse is left/right clicked on certain TrayIcon


Recommended Posts

Greetings...

I want to konw that is there any way to check whether the mouse is left/right clicked on certain TrayIcon.

Or how to get the handle of certain TrayIcon when the TrayIcon is clicked? :D

Thanks very much!

which icon ? an external ones or your scripts ?

[quote]Don't expect for a perfect life ... Expect a least troubles ones[/quote]Contact me : ass@kiss.toWhat I Have Done :Favorites Manager Mangage your favorite's folder, that's coolPC Waker For those who want to save stickersWebScipts Supporter For those who've just started with Web and WebScriptsTemporary Looker Simple but powerful to manage your Temporary folder, you know what you downloaded[UDF] _NumberFormat() Better performance on number display[UDF] _DirGet() What a folder contain [how many (hidden,normal,...) files], with one line of code[UDF] _IsPressEs() Just like _IsPress() but for a group of keys

Link to comment
Share on other sites

Greetings...

I want to konw that is there any way to check whether the mouse is left/right clicked on certain TrayIcon.

Or how to get the handle of certain TrayIcon when the TrayIcon is clicked? :D

Thanks very much!

This?

#include <GuiToolBar.au3>
#include <WinAPI.au3>
#include <Misc.au3>

HotKeySet("{Pause}", "_Exit")

Global $DllHandle = DllOpen("user32.dll")

_SysTray_GetClick("Opera")

;========================================================================================
;
;Function Name:    _SysTray_GetClick()
;Description:      Show what mouse button clicked on certain icon in system tray
;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).
;                  
;Return Value(s):  On success - Write in SciTE console what the mouse button pressed on item
;                  On failure - Error message if required item not found
;Requirement(s):   AutoIt 3.2.10.0
;
;========================================================================================
Func _SysTray_GetClick($sTitle = "")
    If $sTitle = "" Then
        DllClose($DllHandle)
        Return False
    EndIf
    
    Local $hParent, $hChild, $hToolBar, $iCount, $iID = 0, $iText, $iIndex, $iHot
    
    $hParent = _WinAPI_FindWindow("Shell_TrayWnd", "")
    $hChild = ControlGetHandle($hParent, "", "TrayNotifyWnd1")
    $hToolBar = ControlGetHandle($hChild, "", "ToolbarWindow321")
    
    $iCount = _GUICtrlToolbar_ButtonCount($hToolBar)
    
    For $i = 0 To $iCount - 1
        $iID = _GUICtrlToolbar_IndexToCommand($hToolBar, $i)
        $iText = _GUICtrlToolbar_GetButtonText($hToolBar, $iID)
        If StringInStr($iText, $sTitle) Then ExitLoop
    Next
    
    If $iID = 0 Then
        MsgBox(16, "Error", "Required item not found")
        Return False
    EndIf
    
    $iIndex = _GUICtrlToolbar_CommandToIndex($hToolBar, $iID)
    
    While 1
        $iHot = _GUICtrlToolbar_GetHotItem($hToolBar)
        If ($iHot = $iIndex) And (_IsPressed("01", $DllHandle) = 1) Then
            ConsoleWrite("Left mouse button clicked on " & $iText & " item" & @LF)
            Sleep(100)
        ElseIf ($iHot = $iIndex) And (_IsPressed("02", $DllHandle) = 1) Then
            ConsoleWrite("Right mouse button clicked on " & $iText & " item" & @LF)
            Sleep(100)
        EndIf
        Sleep(50)
    WEnd
EndFunc   ;==>_SysTray_GetClick

Func _Exit()
    DllClose($DllHandle)
    Exit
EndFunc
Link to comment
Share on other sites

This?

#include <GuiToolBar.au3>
#include <WinAPI.au3>
#include <Misc.au3>

HotKeySet("{Pause}", "_Exit")

Global $DllHandle = DllOpen("user32.dll")

_SysTray_GetClick("Opera")

;========================================================================================
;
;Function Name:    _SysTray_GetClick()
;Description:      Show what mouse button clicked on certain icon in system tray
;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).
;                  
;Return Value(s):  On success - Write in SciTE console what the mouse button pressed on item
;                  On failure - Error message if required item not found
;Requirement(s):   AutoIt 3.2.10.0
;
;========================================================================================
Func _SysTray_GetClick($sTitle = "")
    If $sTitle = "" Then
        DllClose($DllHandle)
        Return False
    EndIf
    
    Local $hParent, $hChild, $hToolBar, $iCount, $iID = 0, $iText, $iIndex, $iHot
    
    $hParent = _WinAPI_FindWindow("Shell_TrayWnd", "")
    $hChild = ControlGetHandle($hParent, "", "TrayNotifyWnd1")
    $hToolBar = ControlGetHandle($hChild, "", "ToolbarWindow321")
    
    $iCount = _GUICtrlToolbar_ButtonCount($hToolBar)
    
    For $i = 0 To $iCount - 1
        $iID = _GUICtrlToolbar_IndexToCommand($hToolBar, $i)
        $iText = _GUICtrlToolbar_GetButtonText($hToolBar, $iID)
        If StringInStr($iText, $sTitle) Then ExitLoop
    Next
    
    If $iID = 0 Then
        MsgBox(16, "Error", "Required item not found")
        Return False
    EndIf
    
    $iIndex = _GUICtrlToolbar_CommandToIndex($hToolBar, $iID)
    
    While 1
        $iHot = _GUICtrlToolbar_GetHotItem($hToolBar)
        If ($iHot = $iIndex) And (_IsPressed("01", $DllHandle) = 1) Then
            ConsoleWrite("Left mouse button clicked on " & $iText & " item" & @LF)
            Sleep(100)
        ElseIf ($iHot = $iIndex) And (_IsPressed("02", $DllHandle) = 1) Then
            ConsoleWrite("Right mouse button clicked on " & $iText & " item" & @LF)
            Sleep(100)
        EndIf
        Sleep(50)
    WEnd
EndFunc   ;==>_SysTray_GetClick

Func _Exit()
    DllClose($DllHandle)
    Exit
EndFunc

Oh, so great!

It's just the effect I hope to realize... :D

Thank you so much!

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