TrayIcon klicken - (Wie) Geht das?

  • Hallo,
    ich würde gerne ein TrayIcon doppelklicken, leider finde ich keine entsprechende Funktion dafür, und der Code von http://www.autoitscript.com/forum/index.php?showtopic=3229 tuts in meinem Fall auch nicht, da ich ja nicht weiß, mit welchen Parametern ich (wenn überhaupt) ControlFocus() füttern müsste. Eine einfache Angabe des ToolTips reicht ja nicht wies aussieht.
    Das AutoIt Infotool gibt ja nur ToolbarWindow32 zum ganzen Trayiconbereich aus...

    Danke im voraus

  • Sieht leider nicht danach aus:
    ; Functions:
    ; _SysTrayIconCount() - Get count of all systray icons
    ; _SysTrayIconTitles() - Get titles of all programs that have icon on systray
    ; _SysTrayIconProcesses() - Get list of all process names that have icon in systray (hidden or visible)
    ; _SysTrayIconPids() - Get list of all parent process id's that own an icon in systray (hidden or visible)
    ; _SysTrayIconRemove($index) - Remove icon (removes completely, not just hide)
    ; _SysTrayIconIndex($wintitle or $process) - Get icon index based on process name or wintitle
    ; _SysTrayIconTooltip($index) - Get tooltip text of an icon based on index

  • ich machs damit...

    Spoiler anzeigen

    .

    [autoit]

    ;#include <MouseSetOnEvent_UDF.au3>
    #include <StructureConstants.au3>
    #include <Array.au3>
    #include <Systray.au3>

    [/autoit] [autoit][/autoit] [autoit]

    #include <GUIConstantsEx.au3>
    ;#include <WindowsConstants.au3>
    #include <WinAPI.au3>
    #NoTrayIcon

    [/autoit] [autoit][/autoit] [autoit]

    hotkeyset("{ESC}","_exit")

    [/autoit] [autoit][/autoit] [autoit][/autoit] [autoit][/autoit] [autoit]

    $ar = _SysTrayIconCount()
    Dim $Data_Trayicons_visible[$ar][7] ;PID,titel, Prozessname, MouseposX,$mouseposY,Tooltiptext;Index

    [/autoit] [autoit][/autoit] [autoit]

    ;MsgBox(0, @ScriptName, "Bitte einen doppelklick mit der linken Maustaste auf ein Icon im Traybereich ausführen, Ausgabe in der Console")
    $ar2 = _SysTrayIconPids()
    $titles = _systrayicontitles()
    ;~ _arraydisplay($titles,"titel")
    $trayproc = ""
    $m = 0
    $x = ProcessList()
    ;~ _arraydisplay($x)
    ;~ ;MsgBox(0, "", $ar)
    ;~ _ArrayDisplay($ar2)
    For $test = 0 To UBound($ar2) - 1
    For $t = 1 To UBound($x) - 1
    If $ar2[$test] = $x[$t][1] Then
    $pos = _systrayiconpos($test)
    If IsArray($pos) Then ;das icon ist sichtbar!
    $Data_Trayicons_visible[$m][0] = $ar2[$test] ;PID
    $Data_Trayicons_visible[$m][1] = $x[$t][0] ;EXE
    $Data_Trayicons_visible[$m][2] = $titles[$test];Title
    $Data_Trayicons_visible[$m][3] = $pos[0] ;x-koordinate Icon
    $Data_Trayicons_visible[$m][4] = $pos[1] ;y-Koordinate Icon
    $Data_Trayicons_visible[$m][5] = _systrayicontooltip($test); tooltiptext
    $Data_Trayicons_visible[$m][6] = $test ;Index (für z.B) Icon
    $m += 1
    $trayproc &= $x[$t][0] & @CRLF
    ExitLoop
    EndIf
    EndIf
    Next
    Next
    ReDim $Data_Trayicons_visible[$m][7] ;PID,titel, Prozessname, MouseposX,$mouseposY,Tooltiptext
    ;_ArrayDisplay($Data_Trayicons_visible)

    [/autoit] [autoit][/autoit] [autoit][/autoit] [autoit][/autoit] [autoit]

    ;These constants found in the helpfile under Windows Message Codes
    Global Const $WM_MOUSEMOVE = 0x0200 ;mouse move
    Global Const $WM_MOUSEWHEEL = 0x020A ;wheel up/down
    Global Const $WM_LBUTTONDOWN = 0x0201
    Global Const $WM_LBUTTONUP = 0x0202
    Global Const $WM_RBUTTONDOWN = 0x0204
    Global Const $WM_RBUTTONUP = 0x0205
    Global Const $WM_MBUTTONDOWN = 0x0207
    Global Const $WM_MBUTTONUP = 0x0208
    Global Const $MSLLHOOKSTRUCT = $tagPOINT & ";dword mouseData;dword flags;dword time;ulong_ptr dwExtraInfo"

    [/autoit] [autoit][/autoit] [autoit]

    Global $currentEvent[2]

    [/autoit] [autoit][/autoit] [autoit]

    Global $iLBUTTONDOWN = 0
    Global $iRBUTTONDOWN = 0
    Global $iMBUTTONDOWN = 0
    Global $LRClickStatus = 0
    Global $RLClickStatus = 0
    Global $LRDrag = 0
    Global $RLDrag = 0
    Global $LMDrag = 0
    Global $RMDrag = 0
    Global $doubleClickTime = 400

    [/autoit] [autoit][/autoit] [autoit]

    ;Register callback
    $hKey_Proc = DllCallbackRegister("_Mouse_Proc", "int", "int;ptr;ptr")
    $hM_Module = DllCall("kernel32.dll", "hwnd", "GetModuleHandle", "ptr", 0)
    $hM_Hook = DllCall("user32.dll", "hwnd", "SetWindowsHookEx", "int", $WH_MOUSE_LL, "ptr", DllCallbackGetPtr($hKey_Proc), "hwnd", $hM_Module[0], "dword", 0)

    [/autoit] [autoit][/autoit] [autoit][/autoit] [autoit]

    $gui=guicreate("Bitte jetzt ein trayicon doppelklicken")

    [/autoit] [autoit][/autoit] [autoit]

    $label=Guictrlcreatelabel("",10,10,200,200)
    WinSetOnTop($gui,"",1)
    guisetstate()

    [/autoit] [autoit][/autoit] [autoit]

    While 1
    $nMsg = GUIGetMsg()
    If $currentEvent[0] = "LDClick" Then
    $mouse_x = MouseGetPos(0)
    $mouse_y = MouseGetPos(1)
    If $mouse_x > $Data_Trayicons_visible[0][3] And $mouse_y > $Data_Trayicons_visible[0][4] Then ;maus ist im traybereich
    For $i = 0 To UBound($Data_Trayicons_visible) - 2
    If $mouse_x > $Data_Trayicons_visible[$i][3] And $mouse_x < $Data_Trayicons_visible[$i + 1][3] Then ;wenn maus auf einem trayicon ist
    GUICtrlSetData($label,"Icon geklickt: " & $Data_Trayicons_visible[$i][5]&@CRLF)
    $currentEvent[0] = ""
    ExitLoop
    EndIf
    Next
    EndIf
    EndIf


    Switch $nMsg
    Case $GUI_EVENT_CLOSE
    _Exit()
    Exit

    [/autoit] [autoit][/autoit] [autoit]

    EndSwitch
    WEnd

    [/autoit] [autoit][/autoit] [autoit][/autoit] [autoit]

    Func _Mouse_Proc($nCode, $wParam, $lParam)
    Local $info, $mouseData, $time, $timeDiff
    If $nCode < 0 Then
    $ret = DllCall("user32.dll", "long", "CallNextHookEx", "hwnd", $hM_Hook[0], _
    "int", $nCode, "ptr", $wParam, "ptr", $lParam)
    Return $ret[0]
    EndIf

    [/autoit] [autoit][/autoit] [autoit]

    $info = DllStructCreate($MSLLHOOKSTRUCT, $lParam)
    $mouseData = DllStructGetData($info, 3)
    $time = DllStructGetData($info, 5)
    $timeDiff = $time - $currentEvent[1]
    Select
    Case $wParam = $WM_MOUSEMOVE
    ;Test for Drag in here
    If $currentEvent[0] <> "LDrag" Or $currentEvent[0] <> "LRDrag" Or $currentEvent[0] <> "LMDrag" Then
    If $iLBUTTONDOWN = 1 Then
    $currentEvent[0] = "LDrag"
    If $iRBUTTONDOWN = 1 Then
    $currentEvent[0] = "LRDrag"
    $LRDrag = 2
    EndIf
    EndIf
    EndIf
    If $currentEvent[0] <> "RDrag" Or $currentEvent[0] <> "RMDrag" Or $currentEvent[0] <> "LRDrag" Then
    If $iRBUTTONDOWN = 1 Then
    $currentEvent[0] = "RDrag"
    EndIf
    EndIf

    [/autoit] [autoit][/autoit] [autoit]

    If $currentEvent[0] <> "MDrag" Then
    If $iMBUTTONDOWN = 1 Then
    $currentEvent[0] = "MDrag"
    $currentEvent[1] = $time
    EndIf
    EndIf

    [/autoit] [autoit][/autoit] [autoit]

    If $iRBUTTONDOWN = 1 And $iMBUTTONDOWN = 1 And $currentEvent[0] <> "RMDrag" Then
    $RMDrag = 2
    $currentEvent[0] = "RMDrag"
    $currentEvent[1] = $time
    EndIf

    [/autoit] [autoit][/autoit] [autoit]

    If $iLBUTTONDOWN = 1 And $iMBUTTONDOWN = 1 And $currentEvent[0] <> "LMDrag" Then
    $LMDrag = 2
    $currentEvent[0] = "LMDrag"
    $currentEvent[1] = $time
    EndIf

    [/autoit] [autoit][/autoit] [autoit]

    Case $wParam = $WM_MOUSEWHEEL
    If _WinAPI_HiWord($mouseData) > 0 Then
    ;Wheel Up
    $currentEvent[0] = "WheelUp"
    $currentEvent[1] = $time
    Else
    ;Wheel Down
    $currentEvent[0] = "WheelDown"
    $currentEvent[1] = $time
    EndIf

    [/autoit] [autoit][/autoit] [autoit]

    Case $wParam = $WM_LBUTTONDOWN
    ;Register Button Down, check for Right/Left
    If $currentEvent[0] = "RClick" Then
    $LRClickStatus = 1
    EndIf

    [/autoit] [autoit][/autoit] [autoit]

    $iLBUTTONDOWN = 1

    [/autoit] [autoit][/autoit] [autoit][/autoit] [autoit]

    Case $wParam = $WM_LBUTTONUP
    ;Update $iLBUTTONDOWN
    $iLBUTTONDOWN = 0
    ;Test for Right/Left Click
    If $RLClickStatus = 1 And ($timeDiff) < $doubleClickTime Then
    $currentEvent[0] = "RLClick"
    $currentEvent[1] = $time
    EndIf
    If $currentEvent[0] = "LClick" And ($timeDiff) < $doubleClickTime Then
    $currentEvent[0] = "LDClick"
    $currentEvent[1] = $time
    EndIf
    ;Test for Drops
    If $currentEvent[0] = "LDrag" Then
    $currentEvent[0] = "LDrop"
    $currentEvent[1] = $time
    EndIf

    [/autoit] [autoit][/autoit] [autoit]

    If $LRDrag = 2 And $iRBUTTONDOWN = 1 Then
    $LRDrag = 1 ; Denote $LRDrag as still having one button clicked, need to register the drop on RButton up
    EndIf

    [/autoit] [autoit][/autoit] [autoit]

    If $LRDrag = 1 And $iRBUTTONDOWN = 0 Then
    $currentEvent[0] = "LRDrop"
    $currentEvent[1] = $time
    $LRDrag = 0
    EndIf

    [/autoit] [autoit][/autoit] [autoit][/autoit] [autoit][/autoit] [autoit]

    If $LMDrag = 2 And $iMBUTTONDOWN = 1 Then
    $LMDrag = 1 ; Denote $LMDrag as still having one button clicked, need to register the drop on MButton up
    EndIf

    [/autoit] [autoit][/autoit] [autoit]

    If $LMDrag = 1 And $iMBUTTONDOWN = 0 Then
    $currentEvent[0] = "LMDrop"
    $currentEvent[1] = $time
    $LMDrag = 0
    EndIf

    [/autoit] [autoit][/autoit] [autoit]

    ;Set LClick if other events haven't fired
    If $currentEvent[1] <> $time Then
    $currentEvent[0] = "LClick"
    $currentEvent[1] = $time
    EndIf

    [/autoit] [autoit][/autoit] [autoit]

    ;Negate $LRClickStatus
    $RLClickStatus = 0

    [/autoit] [autoit][/autoit] [autoit][/autoit] [autoit][/autoit] [autoit]

    Case $wParam = $WM_RBUTTONDOWN
    ;Register Button Down
    If $currentEvent[0] = "LClick" Then
    $RLClickStatus = 1
    EndIf
    $iRBUTTONDOWN = 1

    [/autoit] [autoit][/autoit] [autoit]

    Case $wParam = $WM_RBUTTONUP
    ;Test for Left, Right, and Right Doubleclick here
    ;Update $iRBUTTONDOWN
    $iRBUTTONDOWN = 0
    ;Test for Right/Left Click
    If $LRClickStatus = 1 And ($timeDiff) < $doubleClickTime Then


    $currentEvent[0] = "LRClick"
    $currentEvent[1] = $time
    EndIf
    If $currentEvent[0] = "RClick" And ($timeDiff) < $doubleClickTime Then
    $currentEvent[0] = "RDClick"
    $currentEvent[1] = $time
    EndIf
    ;Test for Drops
    If $currentEvent[0] = "RDrag" Then
    $currentEvent[0] = "RDrop"
    $currentEvent[1] = $time
    EndIf

    [/autoit] [autoit][/autoit] [autoit]

    If $LRDrag = 2 And $iLBUTTONDOWN = 1 Then
    $LRDrag = 1 ; Denote $LRDrag as still having one button clicked, need to register the drop on RButton up
    EndIf

    [/autoit] [autoit][/autoit] [autoit]

    If $LRDrag = 1 And $iLBUTTONDOWN = 0 Then
    $currentEvent[0] = "LRDrop"
    $currentEvent[1] = $time
    $LRDrag = 0
    EndIf

    [/autoit] [autoit][/autoit] [autoit][/autoit] [autoit][/autoit] [autoit]

    If $RMDrag = 2 And $iMBUTTONDOWN = 1 Then
    $RMDrag = 1 ; Denote $LMDrag as still having one button clicked, need to register the drop on MButton up
    EndIf

    [/autoit] [autoit][/autoit] [autoit]

    If $RMDrag = 1 And $iMBUTTONDOWN = 0 Then
    $currentEvent[0] = "RMDrop"
    $currentEvent[1] = $time
    $RMDrag = 0
    EndIf

    [/autoit] [autoit][/autoit] [autoit]

    ;Set LClick if other events haven't fired
    If $currentEvent[1] <> $time Then
    $currentEvent[0] = "RClick"
    $currentEvent[1] = $time
    EndIf

    [/autoit] [autoit][/autoit] [autoit]

    ;Negate $LRClickStatus
    $LRClickStatus = 0

    [/autoit] [autoit][/autoit] [autoit][/autoit] [autoit]

    Case $wParam = $WM_MBUTTONDOWN
    ;Register Button Down
    $iMBUTTONDOWN = 1

    [/autoit] [autoit][/autoit] [autoit]

    Case $wParam = $WM_MBUTTONUP
    ;Test for Middle Double Click here
    ;Update $iRBUTTONDOWN
    $iMBUTTONDOWN = 0
    ;Test for Right/Left Click
    If $currentEvent[0] = "MClick" And ($timeDiff) < $doubleClickTime Then
    $currentEvent[0] = "MDClick"
    $currentEvent[1] = $time
    EndIf
    ;Test for Drops
    If $currentEvent[0] = "MDrag" Then
    $currentEvent[0] = "MDrop"
    $currentEvent[1] = $time
    EndIf

    [/autoit] [autoit][/autoit] [autoit]

    If $LMDrag = 2 And $iLBUTTONDOWN = 1 Then
    $LMDrag = 1 ; Denote $LRDrag as still having one button clicked, need to register the drop on RButton up
    EndIf

    [/autoit] [autoit][/autoit] [autoit]

    If $LMDrag = 1 And $iLBUTTONDOWN = 0 Then
    $currentEvent[0] = "LMDrop"
    $currentEvent[1] = $time
    $LMDrag = 0
    EndIf

    [/autoit] [autoit][/autoit] [autoit][/autoit] [autoit][/autoit] [autoit]

    If $RMDrag = 2 And $iRBUTTONDOWN = 1 Then
    $RMDrag = 1 ; Denote $LMDrag as still having one button clicked, need to register the drop on MButton up
    EndIf

    [/autoit] [autoit][/autoit] [autoit]

    If $RMDrag = 1 And $iRBUTTONDOWN = 0 Then
    $currentEvent[0] = "RMDrop"
    $currentEvent[1] = $time
    $RMDrag = 0
    EndIf

    [/autoit] [autoit][/autoit] [autoit]

    ;Set MClick if other events haven't fired
    If $currentEvent[1] <> $time Then
    $currentEvent[0] = "MClick"
    $currentEvent[1] = $time
    EndIf

    [/autoit] [autoit][/autoit] [autoit]

    EndSelect

    ;ConsoleWrite($currentEvent[0] & @CRLF & $currentEvent[1]&@crlf)
    ;GUICtrlSetData($Label1, $currentEvent[0] & @CRLF & $currentEvent[1])

    [/autoit] [autoit][/autoit] [autoit]

    $ret = DllCall("user32.dll", "long", "CallNextHookEx", "hwnd", $hM_Hook[0], _
    "int", $nCode, "ptr", $wParam, "ptr", $lParam)
    Return $ret[0]
    EndFunc ;==>_Mouse_Proc

    [/autoit] [autoit][/autoit] [autoit]

    Func _Exit()
    DllCall("user32.dll", "int", "UnhookWindowsHookEx", "hwnd", $hM_Hook[0])
    $hM_Hook[0] = 0
    DllCallbackFree($hKey_Proc)
    $hKey_Proc = 0
    EndFunc ;==>OnAutoItExit

    [/autoit]


    mausposition abfragen und man hat das icon bzw Programm, was unter dem Mauszeiger ist...

    /*EDIT*/ Hoppala, falsches Script gepostet....das ist das richtige^^

    ciao
    Andy


    "Schlechtes Benehmen halten die Leute doch nur deswegen für eine Art Vorrecht, weil keiner ihnen aufs Maul haut." Klaus Kinski
    "Hint: Write comments after each line. So you can (better) see what your program does and what it not does. And we can see what you're thinking what your program does and we can point to the missunderstandings." A-Jay

    Wie man Fragen richtig stellt... Tutorial: Wie man Script-Fehler findet und beseitigt...X-Y-Problem

    Einmal editiert, zuletzt von Andy (19. Oktober 2009 um 22:08)