Jump to content

Global shortcut won't trigger. Appears to only work with certain hardware devices.


Recommended Posts

Hi there, so I have a laptop (Razer Blade) which contains some proprietary software called Synapse. It allows global shortcuts so I can change performance profiles and these trigger fine if I manually enter the shortcut into the hardware keyboard, however they are not triggered if I use automation software such as AutoIT or AutoHotkey.

My question is; are there workarounds for this kind of eventuality, when a command just won't activate?

Link to comment
Share on other sites

  • Moderators

CraftyClown,

Welcome to the AutoIt forums.

Can you please post an example of the code you have tried to run - see here how to do it.

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

10 minutes ago, Nine said:

nope,  that is incorrect...read help file carefully.

 

apologies, I've just jumped over from AHK so I may have got myself confused.

I think this may be a moot point anyway as the shortcuts seem to be restricted to recognised hardware.

Before I spend too long searching the help files, can you let me know if my code is far off?

Link to comment
Share on other sites

  • Moderators

CraftyClown,

As explained in the Help file for Send (HotKeySet uses the same syntax) you only need the braces {} when sending "special keys" - try:

Send("^+1")

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 minute ago, Melba23 said:

CraftyClown,

As explained in the Help file for Send (HotKeySet uses the same syntax) you only need the braces {} when sending "special keys" - try:

Send("^+1")

M23

 

Ah yes of course. Sorry I was quickly copy and pasting there :)

 

The code you just shared was what I was trying, without the curly braces.

 

Unfortunately it doesn't work though. As mentioned before it appears the global shortcuts are restricted to compatible hardware, but I'm wondering if there is a way around that?

Link to comment
Share on other sites

Of course I don't have the hardware so I can't test, but autoit keys should be treated just like you're pushing them on the keyboard. Perhaps there's some logic chip in between the keyboard and where it passes to windows.... 

 

You could try sending the keys to the explorer.exe? 

Link to comment
Share on other sites

Easy test, plug another keyboard into the computer and try using the same keyboard shortcut and see if it works. You can even leave the Razer keyboard in as another test and see if they work without it, and with it.

If I posted any code, assume that code was written using the latest release version unless stated otherwise. Also, if it doesn't work on XP I can't help with that because I don't have access to XP, and I'm not going to.
Give a programmer the correct code and he can do his work for a day. Teach a programmer to debug and he can do his work for a lifetime - by Chirag Gude
How to ask questions the smart way!

I hereby grant any person the right to use any code I post, that I am the original author of, on the autoitscript.com forums, unless I've specifically stated otherwise in the code or the thread post. If you do use my code all I ask, as a courtesy, is to make note of where you got it from.

Back up and restore Windows user files _Array.au3 - Modified array functions that include support for 2D arrays.  -  ColorChooser - An add-on for SciTE that pops up a color dialog so you can select and paste a color code into a script.  -  Customizable Splashscreen GUI w/Progress Bar - Create a custom "splash screen" GUI with a progress bar and custom label.  -  _FileGetProperty - Retrieve the properties of a file  -  SciTE Toolbar - A toolbar demo for use with the SciTE editor  -  GUIRegisterMsg demo - Demo script to show how to use the Windows messages to interact with controls and your GUI.  -   Latin Square password generator

Link to comment
Share on other sites

25 minutes ago, kaisies said:

Of course I don't have the hardware so I can't test, but autoit keys should be treated just like you're pushing them on the keyboard. Perhaps there's some logic chip in between the keyboard and where it passes to windows.... 

 

You could try sending the keys to the explorer.exe? 

Thanks. How would one go about sending the keys to explorer.exe?

Link to comment
Share on other sites

7 minutes ago, BrewManNH said:

Easy test, plug another keyboard into the computer and try using the same keyboard shortcut and see if it works. You can even leave the Razer keyboard in as another test and see if they work without it, and with it.

The Razer keyboard is actually the laptop built in one, but yes I can try hooking up another one and see if that works.

If it doesn't work and this is a hardware limitation, is there any kind of workaround where I can emulate the working hardware?

Link to comment
Share on other sites

2 minutes ago, CraftyClown said:

is there any kind of workaround where I can emulate the working hardware?

My guess would be no.

If I posted any code, assume that code was written using the latest release version unless stated otherwise. Also, if it doesn't work on XP I can't help with that because I don't have access to XP, and I'm not going to.
Give a programmer the correct code and he can do his work for a day. Teach a programmer to debug and he can do his work for a lifetime - by Chirag Gude
How to ask questions the smart way!

I hereby grant any person the right to use any code I post, that I am the original author of, on the autoitscript.com forums, unless I've specifically stated otherwise in the code or the thread post. If you do use my code all I ask, as a courtesy, is to make note of where you got it from.

Back up and restore Windows user files _Array.au3 - Modified array functions that include support for 2D arrays.  -  ColorChooser - An add-on for SciTE that pops up a color dialog so you can select and paste a color code into a script.  -  Customizable Splashscreen GUI w/Progress Bar - Create a custom "splash screen" GUI with a progress bar and custom label.  -  _FileGetProperty - Retrieve the properties of a file  -  SciTE Toolbar - A toolbar demo for use with the SciTE editor  -  GUIRegisterMsg demo - Demo script to show how to use the Windows messages to interact with controls and your GUI.  -   Latin Square password generator

Link to comment
Share on other sites

If you really want to accomplish this still, I'd look at the synapse software itself.  Perhaps the window tool can get a control ID for toggling between the modes, and you can simply emulate a click on that.  Does it live in the taskbar and can you right click -> change whatever your trying to change?

Link to comment
Share on other sites

58 minutes ago, kaisies said:

If you really want to accomplish this still, I'd look at the synapse software itself.  Perhaps the window tool can get a control ID for toggling between the modes, and you can simply emulate a click on that.  Does it live in the taskbar and can you right click -> change whatever your trying to change?

Good call! Yes there is taskbar app that can be left clicked to bring up, however it looks like I need to hover the mouse over the profiles to make them show up. Do you think this would still be possible?

Link to comment
Share on other sites

Below is code I used when I had to try to automate something in the sys tray. Removed things that reference what I was using It for.. it should work once you enter the 3 strings you're looking for.  Of course, if it has a menu, that changes things.  A screenshot would help understand.  I believe this is win10 specific; as the overflow window is called something else.

#include <WinAPI.au3>
#include <GuiMenu.au3>
#include <array.au3>
#include <WindowsConstants.au3>
#include <GuiToolbar.au3>
#include <Process.au3>
#include <Date.au3>
#NoTrayIcon



$L_LogPath = @ScriptDir & "\taskclick.log"

WriteLog("===============================================")
WriteLog("===============================================")
WriteLog("Program Open")
WriteLog("Running as User:" & @UserName & "    Domain: " & @ComputerName)





Opt("WinTitleMatchMode", 2)

Global $iSystray_ButtonNumber
Global $sToolTipTitle = ""  ;When you put your mouse over, what does the tooltop say exactly?
Global $sMenuItemText = ""  ;what does the menu item you want to click say?
Global $sProgramName = ""   ;what is the name of the program (from task manager)



Global $hSysTrayOverflow_Handle = ControlGetHandle('[Class:NotifyIconOverflowWindow]', '', '[Class:ToolbarWindow32;Instance:1]')
If @error Then
    WriteLog("System Overflow tray not found")
    Exit
EndIf

Global $hSysTray_Handle = ControlGetHandle('[Class:Shell_TrayWnd]', '', '[Class:ToolbarWindow32;Instance:1]')
If @error Then
    WriteLog("System Tray not found")
    Exit
EndIf


;msgbox(0,'',@OSVersion)
;If @OSVersion = "WIN_10" Then $hSysTray_Handle = ControlGetHandle('[Class:Shell_TrayWnd]', '', '[ClassnameNN:ToolbarWindow323; INSTANCE:3]')




WriteLog("Overflow Handle: " & $hSysTrayOverflow_Handle)

$iCountInOverFlow = _SysTrayIconCount(2)

For $x = 0 to $iCountInOverFlow
    $sTmpName = _SysTrayIconTooltip($x,2)
    If $sTmpName = $sToolTipTitle Then
        WriteLog("Found it in the overflow. (" & $sToolTipTitle & ")")
        Sleep(1000)
        $hWnd = _FindTrayToolbarWindow(2)
        ControlClick("[CLASS:Shell_TrayWnd; INSTANCE:1]","","[CLASS:Button; INSTANCE:1]","left")
        Sleep(1000)
        $iSystray_ButtonNumber = Get_SystrayOverflow_Index($sToolTipTitle)

        $sText = "Found tooltip (" & $sToolTipTitle & "), at icon count: " & $x  & " and index: " & $iSystray_ButtonNumber
        WriteLog($sText)

        _GUICtrlToolbar_ClickButton2($hSysTrayOverflow_Handle,$iSystray_ButtonNumber,"right")
        FindAndClickPopupMenu()

        Exit
    EndIf
Next



$iCountInToolbar = _SysTrayIconCount(1)

For $x = 0 to $iCountInToolbar
    $handle = _SysTrayIconHandle($x, 1)
    $pid = WinGetProcess($handle)
    $name = _ProcessGetName($pid)
    $sTmpName = _SysTrayIconTooltip($x,1)

    $sMatch = False


    IF $sTmpName = $sToolTipTitle Then $sMatch = True
    ;Msgbox(0,'',"SysTray Icon " & $x & @CRLF & "Program Name (in taskmgr): '" & $name & "'" & @CRLF & "Tooltop: '" & $sTmpName & "'" & @CRLF & $sTmpName & "=" & $sToolTipTitle & "? - " & $sMatch)

    If $sTmpName = $sToolTipTitle Then


        $iSystray_ButtonNumber = Get_Systray_Index($sToolTipTitle)

        $sText = "Found tooltip (" & $sToolTipTitle & "), at icon count: " & $x  & " and index: " & $iSystray_ButtonNumber
        WriteLog($sText)


        _GUICtrlToolbar_ClickButton2($hSysTray_Handle, $iSystray_ButtonNumber, "right",True)

        Sleep(1000)
        FindAndClickPopupMenu()




        Exit
    EndIf
Next


Func _GUICtrlToolbar_ClickButton2($hWnd, $iCommandID, $sButton = "left", $bMove = False, $iClicks = 1, $iSpeed = 1)
    Local $tRect = _GUICtrlToolbar_GetButtonRectEx($hWnd, $iCommandID)
    Local $tPoint = _WinAPI_PointFromRect($tRect)
    $tPoint = _WinAPI_ClientToScreen($hWnd, $tPoint)
    Local $iX, $iY
    _WinAPI_GetXYFromPoint($tPoint, $iX, $iY)
    Local $iMode = Opt("MouseCoordMode", 1)
    If Not $bMove Then
        Local $aPos = MouseGetPos()
        _WinAPI_ShowCursor(False)
        MouseClick($sButton, $iX, $iY, $iClicks, $iSpeed)
        MouseMove($aPos[0], $aPos[1], 0)
        _WinAPI_ShowCursor(True)
    Else
        MouseClick($sButton, $iX, $iY, $iClicks, $iSpeed)
    EndIf
    Opt("MouseCoordMode", $iMode)
EndFunc   ;==>_GUICtrlToolbar_ClickButton


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) = 1 Then ExitLoop
    Next

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

EndFunc


Func Get_SystrayOverflow_Index($sToolTipTitle)


    ; Get systray item count
    Local $iSystray_ButCount = _GUICtrlToolbar_ButtonCount($hSysTrayOverflow_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($hSysTrayOverflow_Handle, $iSystray_ButtonNumber), $sToolTipTitle) = 1 Then ExitLoop
    Next

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

EndFunc



Func FindAndClickPopupMenu()
    Local $aPopUp_List = _WinAPI_EnumWindowsPopup()
    ;_arraydisplay($aPopUp_List)
    ;Exit
    Local $hWnd = $aPopUp_List[1][0]
    Local $sClass = $aPopUp_List[1][1]
    WriteLog("WindowsPopupClass: " & $sClass)
    If $sClass = "#32768" Then; Return $hWnd
        WriteLog("Found correct class" & @CRLF)
        $hMenu = _SendMessage($hWnd, $MN_GETHMENU, 0, 0)
        If _GUICtrlMenu_IsMenu($hMenu) Then
            $iCount = _GUICtrlMenu_GetItemCount($hMenu)
            Local $aPopUp_Text[1] = [0]
            For $j = 0 To $iCount - 1
                WriteLog(_GUICtrlMenu_GetItemType($hMenu, $j, True))
                If Not _GUICtrlMenu_GetItemType($hMenu, $j, True) = $MFT_SEPARATOR Then
                    $aPopUp_Text[0] += 1
                    ReDim $aPopUp_Text[$aPopUp_Text[0] + 1]
                    If _GUICtrlMenu_GetItemText($hMenu, $j) = $sMenuItemText Then

                        $aPos = _GUICtrlMenu_GetItemRect($hWnd, $hMenu, $j)
                        $iOldOpt = Opt("MouseCoordMode", 0)
                        MouseClick("primary", $aPos[0]+2, $aPos[1]+2, 1, 0) ; Adjust the speed to suit
                        Return True
                    EndIf
                    WriteLog("Item " & $j & " = " & _GUICtrlMenu_GetItemText($hMenu, $j))
                EndIf
            Next
        EndIf
    EndIf
    Return False

EndFunc



#include-once
; ----------------------------------------------------------------------------
;
; Author:         Tuape
; Modified:       Erik Pilsits
;
; Script Function:
;   Systray UDF - Functions for reading icon info from system tray / removing
;   any icon.
;
; Last Update: 5/13/2013
;
; ----------------------------------------------------------------------------

;===============================================================================
;
; Function Name:    _SysTrayIconCount($iWin = 1)
; Description:      Returns number of icons on systray
;                   Note: Hidden icons are also reported
; Parameter(s):     $iWin
;                   | 1         - ToolbarWindow32, Win2000+
;                   | 2         - NotifyIconOverflowWindow, Win7+
;
; Requirement(s):
; Return Value(s):  On Success - Returns number of icons found
;                   On Failure - Returns -1
;
; Author(s):        Tuape, Erik Pilsits
;
;===============================================================================
Func _SysTrayIconCount($iWin = 1)
    Local Const $TB_BUTTONCOUNT = 1048
    Local $hWnd = _FindTrayToolbarWindow($iWin)
    If $hWnd = -1 Then Return -1
    Local $count = DllCall("user32.dll", "lresult", "SendMessageW", "hwnd", $hWnd, "uint", $TB_BUTTONCOUNT, "wparam", 0, "lparam", 0)
    If @error Then Return -1
    Return $count[0]
EndFunc   ;==>_SysTrayIconCount

;===============================================================================
;
; Function Name:    _SysTrayIconTitles($iWin = 1)
; Description:      Get list of all window titles that have systray icon
; Parameter(s):     $iWin
;                   | 1         - ToolbarWindow32, Win2000+
;                   | 2         - NotifyIconOverflowWindow, Win7+
; Requirement(s):
; Return Value(s):  On Success - Returns an array with all window titles
;                   On Failure - Returns -1
;
; Author(s):        Tuape, Erik Pilsits
;
;===============================================================================
Func _SysTrayIconTitles($iWin = 1)
    Local $count = _SysTrayIconCount($iWin)
    If $count <= 0 Then Return -1
    Local $titles[$count]
    ; Get icon owner window"s title
    For $i = 0 To $count - 1
        $titles[$i] = WinGetTitle(_SysTrayIconHandle($i, $iWin))
    Next
    Return $titles
EndFunc   ;==>_SysTrayIconTitles

;===============================================================================
;
; Function Name:    _SysTrayIconPids($iWin = 1)
; Description:      Get list of all processes id's that have systray icon
; Parameter(s):     $iWin
;                   | 1         - ToolbarWindow32, Win2000+
;                   | 2         - NotifyIconOverflowWindow, Win7+
; Requirement(s):
; Return Value(s):  On Success - Returns an array with all process id's
;                   On Failure - Returns -1
;
; Author(s):        Tuape, Erik Pilsits
;
;===============================================================================
Func _SysTrayIconPids($iWin = 1)
    Local $count = _SysTrayIconCount($iWin)
    If $count <= 0 Then Return -1
    Local $processes[$count]
    For $i = 0 To $count - 1
        $processes[$i] = WinGetProcess(_SysTrayIconHandle($i, $iWin))
    Next
    Return $processes
EndFunc   ;==>_SysTrayIconPids

;===============================================================================
;
; Function Name:    _SysTrayIconProcesses($iWin = 1)
; Description:      Get list of all processes that have systray icon
; Parameter(s):     $iWin
;                   | 1         - ToolbarWindow32, Win2000+
;                   | 2         - NotifyIconOverflowWindow, Win7+
; Requirement(s):
; Return Value(s):  On Success - Returns an array with all process names
;                   On Failure - Returns -1
;
; Author(s):        Tuape, Erik Pilsits
;
;===============================================================================
Func _SysTrayIconProcesses($iWin = 1)
    Local $pids = _SysTrayIconPids($iWin)
    If Not IsArray($pids) Then Return -1
    Local $processes[UBound($pids)]
    ; List all processes
    Local $list = ProcessList()
    For $i = 0 To UBound($pids) - 1
        For $j = 1 To $list[0][0]
            If $pids[$i] = $list[$j][1] Then
                $processes[$i] = $list[$j][0]
                ExitLoop
            EndIf
        Next
    Next
    Return $processes
EndFunc   ;==>_SysTrayIconProcesses

;===============================================================================
;
; Function Name:    _SysTrayIconIndex($test, $mode = 0, $iWin = 1)
; Description:      Get list of all processes id"s that have systray icon
; Parameter(s):     $test       - process name / window title text / process PID
;                   $mode
;                   | 0         - get index by process name (default)
;                   | 1         - get index by window title
;                   | 2         - get index by process PID
;                   $iWin
;                   | 1         - ToolbarWindow32, Win2000+
;                   | 2         - NotifyIconOverflowWindow, Win7+
; Requirement(s):
; Return Value(s):  On Success - Returns index of found icon
;                   On Failure - Returns -1
;
; Author(s):        Tuape, Erik Pilsits
;
;===============================================================================
Func _SysTrayIconIndex($test, $mode = 0, $iWin = 1)
    Local $ret = -1, $compare = -1
    If $mode < 0 Or $mode > 2 Or Not IsInt($mode) Then Return -1
    Switch $mode
        Case 0
            $compare = _SysTrayIconProcesses($iWin)
        Case 1
            $compare = _SysTrayIconTitles($iWin)
        Case 2
            $compare = _SysTrayIconPids($iWin)
    EndSwitch
    If Not IsArray($compare) Then Return -1
    For $i = 0 To UBound($compare) - 1
        If $compare[$i] = $test Then
            $ret = $i
            ExitLoop
        EndIf
    Next
    Return $ret
EndFunc   ;==>_SysTrayIconIndex

; INTERNAL =====================================================================
;
; Function Name:    _SysTrayGetButtonInfo($iIndex, $iWin = 1, $iInfo = 0)
; Description:      Gets Tray Button Info
; Parameter(s):     $iIndex     - icon index (Note: starting from 0)
;                   $iWin
;                   | 1         - ToolbarWindow32, Win2000+
;                   | 2         - NotifyIconOverflowWindow, Win7+
;                   $iInfo      - Info to return
;                   | 1         - TBBUTTON structure
;                   | 2         - TRAYDATA structure
;                   | 3         - tooltip
;                   | 4         - icon position
; Requirement(s):
; Return Value(s):  On Success - Returns requested info
;                   On Failure - Sets @error and returns -1
;                   | 1        - Failed to find tray window
;                   | 2        - Failed to get tray window PID
;                   | 3        - Failed to open process
;                   | 4        - Failed to allocate memory
;                   | 5        - Failed to get TBBUTTON info
;
; Author(s):        Erik Pilsits, Tuape
;
;===============================================================================
Func _SysTrayGetButtonInfo($iIndex, $iWin = 1, $iInfo = 1)
    Local Const $TB_GETBUTTON = 1047
;~  Local Const $TB_GETBUTTONTEXT = 1099
;~  Local Const $TB_GETBUTTONINFO = 1089
    Local Const $TB_GETITEMRECT = 1053
    Local Const $ACCESS = BitOR(0x0008, 0x0010, 0x0400) ; VM_OPERATION, VM_READ, QUERY_INFORMATION
    Local $TBBUTTON
    If @OSArch = "X86" Then
        $TBBUTTON = DllStructCreate("int iBitmap;int idCommand;byte fsState;byte fsStyle;byte bReserved[2];dword dwData;int iString")
    Else ; X64
        $TBBUTTON = DllStructCreate("int iBitmap;int idCommand;byte fsState;byte fsStyle;byte bReserved[6];uint64 dwData;int64 iString")
    EndIf
    Local $TRAYDATA
    If @OSArch = "X86" Then
        $TRAYDATA = DllStructCreate("hwnd hwnd;uint uID;uint uCallbackMessage;dword Reserved[2];handle hIcon")
    Else
        $TRAYDATA = DllStructCreate("uint64 hwnd;uint uID;uint uCallbackMessage;dword Reserved[2];uint64 hIcon")
    EndIf
    Local $trayHwnd = _FindTrayToolbarWindow($iWin)
    If $trayHwnd = -1 Then Return SetError(1, 0, -1)
    Local $return, $err = 0
    Local $ret = DllCall("user32.dll", "dword", "GetWindowThreadProcessId", "hwnd", $trayHwnd, "dword*", 0)
    If @error Or Not $ret[2] Then SetError(2, 0, -1)
    Local $pId = $ret[2]
    Local $procHandle = DllCall("kernel32.dll", "handle", "OpenProcess", "dword", $ACCESS, "bool", False, "dword", $pId)
    If @error Or Not $procHandle[0] Then Return SetError(3, 0, -1)
    Local $lpData = DllCall("kernel32.dll", "ptr", "VirtualAllocEx", "handle", $procHandle[0], "ptr", 0, "ulong", DllStructGetSize($TBBUTTON), "dword", 0x1000, "dword", 0x04)
    If Not @error And $lpData[0] Then
        $ret = DllCall("user32.dll", "lresult", "SendMessageW", "hwnd", $trayHwnd, "uint", $TB_GETBUTTON, "wparam", $iIndex, "lparam", $lpData[0])
        If Not @error And $ret[0] Then
            DllCall("kernel32.dll", "bool", "ReadProcessMemory", "handle", $procHandle[0], "ptr", $lpData[0], "struct*", $TBBUTTON, "ulong", DllStructGetSize($TBBUTTON), "ulong*", 0)
            Switch $iInfo
                Case 2
                    ; TRAYDATA structure
                    DllCall("kernel32.dll", "bool", "ReadProcessMemory", "handle", $procHandle[0], "ptr", DllStructGetData($TBBUTTON, 6), "struct*", $TRAYDATA, "ulong", DllStructGetSize($TRAYDATA), "ulong*", 0)
                    $return = $TRAYDATA
                Case 3
                    ; tooltip
                    $return = ""
                    If BitShift(DllStructGetData($TBBUTTON, 7), 16) <> 0 Then
                        Local $intTip = DllStructCreate("wchar[1024]")
                        ; we have a pointer to a string, otherwise it is an internal resource identifier
                        DllCall("kernel32.dll", "bool", "ReadProcessMemory", "handle", $procHandle[0], "ptr", DllStructGetData($TBBUTTON, 7), "struct*", $intTip, "ulong", DllStructGetSize($intTip), "ulong*", 0)
                        $return = DllStructGetData($intTip, 1)
                    ;else internal resource
                    EndIf
                Case 4
                    ; icon position
                    If Not BitAND(DllStructGetData($TBBUTTON, 3), 8) Then ; 8 = TBSTATE_HIDDEN
                        Local $pos[2], $RECT = DllStructCreate("int;int;int;int")
                        DllCall("user32.dll", "lresult", "SendMessageW", "hwnd", $trayHwnd, "uint", $TB_GETITEMRECT, "wparam", $iIndex, "lparam", $lpData[0])
                        DllCall("kernel32.dll", "bool", "ReadProcessMemory", "handle", $procHandle[0], "ptr", $lpData[0], "struct*", $RECT, "ulong", DllStructGetSize($RECT), "ulong*", 0)
                        $ret = DllCall("user32.dll", "int", "MapWindowPoints", "hwnd", $trayHwnd, "ptr", 0, "struct*", $RECT, "uint", 2)
                        $pos[0] = DllStructGetData($RECT, 1)
                        $pos[1] = DllStructGetData($RECT, 2)
                        $return = $pos
                    Else
                        $return = -1
                    EndIf
                Case Else
                    ; TBBUTTON
                    $return = $TBBUTTON
            EndSwitch
        Else
            $err = 5
        EndIf
        DllCall("kernel32.dll", "bool", "VirtualFreeEx", "handle", $procHandle[0], "ptr", $lpData[0], "ulong", 0, "dword", 0x8000)
    Else
        $err = 4
    EndIf
    DllCall("kernel32.dll", "bool", "CloseHandle", "handle", $procHandle[0])
    If $err Then
        Return SetError($err, 0, -1)
    Else
        Return $return
    EndIf
EndFunc   ;==>_SysTrayGetButtonInfo

;===============================================================================
;
; Function Name:    _SysTrayIconHandle($iIndex, $iWin = 1)
; Description:      Gets hwnd of window associated with systray icon of given index
; Parameter(s):     $iIndex     - icon index (Note: starting from 0)
;                   $iWin
;                   | 1         - ToolbarWindow32, Win2000+
;                   | 2         - NotifyIconOverflowWindow, Win7+
;
; Requirement(s):
; Return Value(s):  On Success - Returns hwnd of found icon
;                   On Failure - Sets @error and returns -1
;                   | See _SysTrayGetButtonInfo for @error returns
;
; Author(s):        Tuape, Erik Pilsits
;
;===============================================================================
Func _SysTrayIconHandle($iIndex, $iWin = 1)
    Local $TRAYDATA = _SysTrayGetButtonInfo($iIndex, $iWin, 2)
    If @error Then
        Return SetError(@error, 0, -1)
    Else
        Return Ptr(DllStructGetData($TRAYDATA, 1))
    EndIf
EndFunc   ;==>_SysTrayIconHandle

;===============================================================================
;
; Function Name:    _SysTrayIconTooltip($iIndex, $iWin = 1)
; Description:      Gets the tooltip text of systray icon of given index
; Parameter(s):     $iIndex     - icon index (Note: starting from 0)
;                   $iWin
;                   | 1         - ToolbarWindow32, Win2000+
;                   | 2         - NotifyIconOverflowWindow, Win7+
;
; Requirement(s):
; Return Value(s):  On Success - Returns tooltip text of icon
;                   On Failure - Sets @error and returns -1
;                   | See _SysTrayGetButtonInfo for @error returns
;
; Author(s):        Tuape, Erik Pilsits
;
;===============================================================================
Func _SysTrayIconTooltip($iIndex, $iWin = 1)
    Local $ret = _SysTrayGetButtonInfo($iIndex, $iWin, 3)
    If @error Then
        Return SetError(@error, 0, -1)
    Else
        Return $ret
    EndIf
EndFunc   ;==>_SysTrayIconTooltip

;===============================================================================
;
; Function Name:    _SysTrayIconPos($iIndex, $iWin = 1)
; Description:      Gets x & y position of systray icon
; Parameter(s):     $iIndex     - icon index (Note: starting from 0)
;                   $iWin
;                   | 1         - ToolbarWindow32, Win2000+
;                   | 2         - NotifyIconOverflowWindow, Win7+
;
; Requirement(s):
; Return Value(s):  On Success - Returns array, x [0] and y [1] position of icon
;                   On Failure - Sets @error and returns -1
;                   | -1       - Icon is hidden (Autohide on XP, etc)
;                   | See _SysTrayGetButtonInfo for additional @error returns
;
; Author(s):        Tuape, Erik Pilsits
;
;===============================================================================
Func _SysTrayIconPos($iIndex, $iWin = 1)
    Local $ret = _SysTrayGetButtonInfo($iIndex, $iWin, 4)
    If @error Then
        Return SetError(@error, 0, -1)
    Else
        If $ret = -1 Then
            Return SetError(-1, 0, -1)
        Else
            Return $ret
        EndIf
    EndIf
EndFunc   ;==>_SysTrayIconPos

;===============================================================================
;
; Function Name:    _SysTrayIconVisible($iIndex, $iWin = 1)
; Description:      Gets the visibility of a systray icon
; Parameter(s):     $iIndex     - icon index (Note: starting from 0)
;                   $iWin
;                   | 1         - ToolbarWindow32, Win2000+
;                   | 2         - NotifyIconOverflowWindow, Win7+
;
; Requirement(s):
; Return Value(s):  On Success - Returns True (visible) or False (hidden)
;                   On Failure - Sets @error and returns -1
;                   | See _SysTrayGetButtonInfo for @error returns
;
; Author(s):        Tuape, Erik Pilsits
;
;===============================================================================
Func _SysTrayIconVisible($iIndex, $iWin = 1)
    Local $TBBUTTON = _SysTrayGetButtonInfo($iIndex, $iWin, 1)
    If @error Then
        Return SetError(@error, 0, -1)
    Else
        Return Not BitAND(DllStructGetData($TBBUTTON, 3), 8) ;TBSTATE_HIDDEN
    EndIf
EndFunc   ;==>_SysTrayIconVisible

;===============================================================================
;
; Function Name:    _SysTrayIconHide($index, $iFlag, $iWin = 1)
; Description:      Hides / unhides any icon on systray
;
; Parameter(s):     $index      - icon index. Can be queried with _SysTrayIconIndex()
;                   $iFlag      - hide (1) or show (0) icon
;                   $iWin
;                   | 1         - ToolbarWindow32, Win2000+
;                   | 2         - NotifyIconOverflowWindow, Win7+
;
; Requirement(s):
; Return Value(s):  On Success - Returns 1 if operation was successfull or 0 if
;                   icon was already hidden/unhidden
;                   On Failure - Sets @error and returns -1
;                   | See _SysTrayGetButtonInfo for @error returns
;
; Author(s):        Tuape, Erik Pilsits
;
;===============================================================================
Func _SysTrayIconHide($index, $iFlag, $iWin = 1)
;~     Local Const $TB_HIDEBUTTON = 0x0404 ; WM_USER + 4
    Local $TBBUTTON = _SysTrayGetButtonInfo($index, $iWin, 1)
    If @error Then Return SetError(@error, 0, -1)
    Local $visible = Not BitAND(DllStructGetData($TBBUTTON, 3), 8) ;TBSTATE_HIDDEN
    If ($iFlag And Not $visible) Or (Not $iFlag And $visible) Then
        Return 0
    Else
        Local $TRAYDATA = _SysTrayGetButtonInfo($index, $iWin, 2)
        If @error Then Return SetError(@error, 0, -1)
        Local $NOTIFYICONDATA = DllStructCreate("dword cbSize;hwnd hWnd;uint uID;uint uFlags;uint uCallbackMessage;handle hIcon;wchar szTip[128];" _
            & "dword dwState;dword dwStateMask;wchar szInfo[256];uint uVersion;wchar szInfoTitle[64];dword dwInfoFlags;" _
            & "STRUCT;ulong;ushort;ushort;byte[8];ENDSTRUCT;handle hBalloonIcon")
        DllStructSetData($NOTIFYICONDATA, 1, DllStructGetSize($NOTIFYICONDATA))
        DllStructSetData($NOTIFYICONDATA, 2, Ptr(DllStructGetData($TRAYDATA, 1)))
        DllStructSetData($NOTIFYICONDATA, 3, DllStructGetData($TRAYDATA, 2))
        DllStructSetData($NOTIFYICONDATA, 4, 8) ; NIF_STATE
        DllStructSetData($NOTIFYICONDATA, 8, $iFlag) ; dw_State, 0 or 1 = NIS_HIDDEN
        DllStructSetData($NOTIFYICONDATA, 9, 1) ; dwStateMask
        Local $ret = DllCall("shell32.dll", "bool", "Shell_NotifyIconW", "dword", 0x1, "struct*", $NOTIFYICONDATA) ; NIM_MODIFY
        DllCall("user32.dll", "lresult", "SendMessageW", "hwnd", WinGetHandle("[CLASS:Shell_TrayWnd]"), "uint", 0x001A, "wparam", 0, "lparam", 0) ; WM_SETTINGCHANGE
        If IsArray($ret) And $ret[0] Then
            Return 1
        Else
            Return 0
        EndIf
;~      $ret = DllCall("user32.dll", "lresult", "SendMessageW", "hwnd", $trayHwnd, "uint", $TB_HIDEBUTTON, "wparam", DllStructGetData($TBBUTTON, 2), "lparam", $iHide)
;~      If @error Or Not $ret[0] Then
;~          $return = -1
;~      Else
;~          $return = $ret[0]
;~      EndIf
    EndIf
EndFunc   ;==>_SysTrayIconHide

;===============================================================================
;
; Function Name:    _SysTrayIconMove($curPos, $newPos, $iWin = 1)
; Description:      Moves systray icon
;
; Parameter(s):     $curPos     - icon's current index (0 based)
;                   $newPos     - icon's new position
;                                 ($curPos+1 = one step to right, $curPos-1 = one step to left)
;                   $iWin
;                   | 1         - ToolbarWindow32, Win2000+
;                   | 2         - NotifyIconOverflowWindow, Win7+
;
; Requirement(s):   AutoIt3 Beta
; Return Value(s):  On Success - Returns 1 if operation was successfull, 0 if not
;                   On Failure - Sets @error and returns -1
;                   | 1        - Bad parameters
;                   | 2        - Failed to find tray window
;
; Author(s):        Tuape, Erik Pilsits
;
;===============================================================================
Func _SysTrayIconMove($curPos, $newPos, $iWin = 1)
    Local Const $TB_MOVEBUTTON = 0x0452 ; WM_USER + 82
    Local $iconCount = _SysTrayIconCount($iWin)
    If $curPos < 0 Or $newPos < 0 Or $curPos > $iconCount - 1 Or $newPos > $iconCount - 1 Or Not IsInt($curPos) Or Not IsInt($newPos) Then Return SetError(1, 0, -1)
    Local $hWnd = _FindTrayToolbarWindow($iWin)
    If $hWnd = -1 Then Return SetError(2, 0, -1)
    Local $ret = DllCall("user32.dll", "lresult", "SendMessageW", "hwnd", $hWnd, "uint", $TB_MOVEBUTTON, "wparam", $curPos, "lparam", $newPos)
    If @error Or Not $ret[0] Then
        Return 0
    Else
        Return 1
    EndIf
EndFunc   ;==>_SysTrayIconMove

;===============================================================================
;
; Function Name:    _SysTrayIconRemove($index, $iWin = 1)
; Description:      Removes systray icon completely.
;
; Parameter(s):     $index      - Icon index (first icon is 0)
;                   $iWin
;                   | 1         - ToolbarWindow32, Win2000+
;                   | 2         - NotifyIconOverflowWindow, Win7+
;
; Return Value(s):  On Success - Returns 1 if icon successfully removed, 0 if not
;                   On Failure - Sets @error and returns -1
;                   | See _SysTrayGetButtonInfo for @error returns
;
; Author(s):        Tuape, Erik Pilsits
;
;===============================================================================
Func _SysTrayIconRemove($index, $iWin = 1)
    Local Const $TB_DELETEBUTTON = 1046
    Local $TRAYDATA = _SysTrayGetButtonInfo($index, $iWin, 2)
    If @error Then Return SetError(@error, 0, -1)
    Local $NOTIFYICONDATA = DllStructCreate("dword cbSize;hwnd hWnd;uint uID;uint uFlags;uint uCallbackMessage;handle hIcon;wchar szTip[128];" _
        & "dword dwState;dword dwStateMask;wchar szInfo[256];uint uVersion;wchar szInfoTitle[64];dword dwInfoFlags;" _
        & "STRUCT;ulong;ushort;ushort;byte[8];ENDSTRUCT;handle hBalloonIcon")
    DllStructSetData($NOTIFYICONDATA, 1, DllStructGetSize($NOTIFYICONDATA))
    DllStructSetData($NOTIFYICONDATA, 2, Ptr(DllStructGetData($TRAYDATA, 1)))
    DllStructSetData($NOTIFYICONDATA, 3, DllStructGetData($TRAYDATA, 2))
    Local $ret = DllCall("shell32.dll", "bool", "Shell_NotifyIconW", "dword", 0x2, "struct*", $NOTIFYICONDATA) ; NIM_DELETE
    DllCall("user32.dll", "lresult", "SendMessageW", "hwnd", WinGetHandle("[CLASS:Shell_TrayWnd]"), "uint", 0x001A, "wparam", 0, "lparam", 0) ; WM_SETTINGCHANGE
    If IsArray($ret) And $ret[0] Then
        Return 1
    Else
        Return 0
    EndIf
;~  Local $hWnd = _FindTrayToolbarWindow($iWin)
;~  If $hwnd = -1 Then Return -1
;~  Local $ret = DllCall("user32.dll", "lresult", "SendMessageW", "hwnd", $hWnd, "uint", $TB_DELETEBUTTON, "wparam", $index, "lparam", 0)
;~  If @error Or Not $ret[0] Then Return -1
;~  Return $ret[0]
EndFunc   ;==>_SysTrayIconRemove

;===============================================================================
;
; Function Name:    _FindTrayToolbarWindow($iWin = 1)
; Description:      Utility function for finding Toolbar window hwnd
; Parameter(s):     $iWin
;                   | 1         - ToolbarWindow32, Win2000+
;                   | 2         - NotifyIconOverflowWindow, Win7+
;
; Requirement(s):
; Return Value(s):  On Success - Returns Toolbar window hwnd
;                   On Failure - returns -1
;
; Author(s):        Tuape, Erik Pilsits
;
;===============================================================================
Func _FindTrayToolbarWindow($iWin = 1)
    Local $hwnd, $ret = -1
    If $iWin = 1 Then
        $hWnd = DllCall("user32.dll", "hwnd", "FindWindow", "str", "Shell_TrayWnd", "ptr", 0)
        If @error Then Return -1
        $hWnd = DllCall("user32.dll", "hwnd", "FindWindowEx", "hwnd", $hWnd[0], "hwnd", 0, "str", "TrayNotifyWnd", "ptr", 0)
        If @error Then Return -1
        If @OSVersion <> "WIN_2000" Then
            $hWnd = DllCall("user32.dll", "hwnd", "FindWindowEx", "hwnd", $hWnd[0], "hwnd", 0, "str", "SysPager", "ptr", 0)
            If @error Then Return -1
        EndIf
        $hWnd = DllCall("user32.dll", "hwnd", "FindWindowEx", "hwnd", $hWnd[0], "hwnd", 0, "str", "ToolbarWindow32", "ptr", 0)
        If @error Then Return -1
        $ret = $hwnd[0]
    ElseIf $iWin = 2 Then
        ; NotifyIconOverflowWindow for Windows 7
        $hWnd = DllCall("user32.dll", "hwnd", "FindWindow", "str", "NotifyIconOverflowWindow", "ptr", 0)
        If @error Then Return -1
        $hWnd = DllCall("user32.dll", "hwnd", "FindWindowEx", "hwnd", $hWnd[0], "hwnd", 0, "str", "ToolbarWindow32", "ptr", 0)
        If @error Then Return -1
        $ret = $hwnd[0]
    EndIf
    Return $ret
EndFunc   ;==>_FindTrayToolbarWindow



Func WriteLog($sText,$bUpdateSplash = False)
;~  StringReplace("                   ")  ;Need to fix this to pad @CRLF

    Local $i


    Local $sTmp = ""
    If Not FileCreate($L_LogPath, _DateTimeFormat(_NowCalc(), 2) & " " & _DateTimeFormat(_NowCalc(), 5) & " Task Click, First Run" & @CRLF) Then

        ;MsgBox($MB_ICONERROR, "", "No log file exists, and an error occured while trying to create one!!!")
        Return False
    EndIf

    ; Open the file for writing (append to the end of a file) and store the handle to a variable.
    Local $hFileOpen = FileOpen($L_LogPath, $FO_APPEND)
    If $hFileOpen = -1 Then
        ;MsgBox($MB_ICONERROR, "", "An error occurred when reading the file.")
        Return False
    EndIf

    If Isarray($sText) Then
        For $i = 0 to UBound($sText)-1
            $sTmp &= $sText[$i] & @TAB
        Next
        $sText = $sTmp
    EndIf

    $aTmp = StringSplit($sText,@CRLF)
    If Not @Error Then
        $sTmp = ""
        For $i = 1 to $aTmp[0]
            If $i == $aTmp[0] Then
                $sTmp &= StringReplace($aTmp[$i],@CRLF,"")
            Else
                $sTmp &= StringReplace($aTmp[$i],@CRLF,"") & @CRLF & "                              "
            EndIf
        Next
        $sText = $sTmp
    EndIf


    FileWriteLine($hFileOpen, _DateTimeFormat(_NowCalc(), 2) & " " & _DateTimeFormat(_NowCalc(), 5) & "  " & $sText)
    FileClose($hFileOpen)
EndFunc


Func FileCreate($sFilePath, $sString)
    Local $fReturn = True ; Create a variable to store a boolean value.
    If FileExists($sFilePath) = 0 Then $fReturn = FileWrite($sFilePath, $sString) = 1 ; If FileWrite returned 1 this will be True otherwise False.
    Return $fReturn ; Return the boolean value of either True of False, depending on the return value of FileWrite.
EndFunc   ;==>FileCreate

 

Link to comment
Share on other sites

1 hour ago, kaisies said:

By taskbar, you to mean in the system tray? (Bottom right next to clock)

 

Sorry, yes of course I meant the system tray.

As you can see from the screen grab the mouse needs to hover over the triangle on the right edge of the profile, to reveal the three profile options to the left. The mouse then needs to glide to the left to select the relevant profile. 

Will all these mouse movements make automation of this kind difficult?

Screenshot (56).png

Edited by CraftyClown
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...