Jump to content

Tray Menu and Hotkeys


Recommended Posts

I have a script which is not very good written and could be mouch smaller etc. but thats not the point.

The Problem is that sometimes my script stuck and the reason is i am using a tray menu and hotkeys to call other functions...

Is there a way, to only allow a new hotkey function to get started when the other stopped? 

Or a way to always return to the tray menu? 
 

#RequireAdmin
#include <StringConstants.au3>
#include <TrayConstants.au3>
#include <Process.au3>
#include <File.au3>
#include <FileConstants.au3>
#include "ScalingMessageBox.au3"
#include "_GetCurrentSoundDevice.au3"
#include <Array.au3>
#include <WinAPI.au3>
#include <_MuteActiveWindow.au3>

Opt("TrayMenuMode", 3)
Opt("TrayIconDebug", 1)

Global $IsMinimized = 0
Global $ActualWindow

HotKeySet("+!s", "SwitchSoundDevice") ; Shift-Alt-t. - Hotkey to switch between devices.
HotKeySet("+!k", "AppMinMax") ; Shift-Alt-k. - Hotkey to minimize/maximize current app.
HotKeySet("+!t", "Taskkiller") ; Shift-Alt-t. - Hotkey to kill current app.
HotKeySet("+!f", "SteamFriends") ; Shift-Alt-f. - Hotkey to open Steam Friends.
HotKeySet("+!n", "Notepad") ; Shift-Alt-N. - Hotkey for Notepad Function.
HotKeySet("+!m", "_MuteActiveWindow") ; Shift-Alt-M. - Hotkey to mute active window sound.
HotKeySet("+!c", "SciTEClipboard") ; Shift-Alt-M. - Hotkey to mute active window sound.

If Not ProcessExists("aida64.exe") Or Not ProcessExists("RemotePanel.exe") Or Not ProcessExists("PerfTune.exe") Then local AutoStart()
local $dcPID[3]
$dcPID[0] = 2
$dcPID[1] = ShellExecute("D:\Batch Space\WindowsAutomation\DownloadControl.au3")
$dcPID[2] = ShellExecute("D:\Batch Space\WindowsAutomation\FrapsMessage.au3")
SwitchSoundDevice("Speaker") ;-> Selecting Speaker on Startup.

Local $iSteam = TrayCreateItem("Steam")
    TrayCreateItem("") ; Create a separator line.
Local $iMobileAuthenticator = TrayCreateItem("Mobile Authenticator")
    TrayCreateItem("") ; Create a separator line.
Local $iGames = TrayCreateMenu("Games") ; Create a tray menu sub menu with two sub items.
Local $iPUBG = TrayCreateItem("PLAYERUNKNOWN'S BATTLEGROUNDS", $iGames)
Local $iDARWIN = TrayCreateItem("Darwin Project", $iGames)
Local $iFORTNITE = TrayCreateItem("Fortnite Battle Royale", $iGames)
    TrayCreateItem("") ; Create a separator line.
Local $iStopWatch = TrayCreateItem("StopWatch")
    TrayCreateItem("") ; Create a separator line.
Local $iTimer = TrayCreateItem("Timer")
    TrayCreateItem("") ; Create a separator line.
Local $iTaskManager = TrayCreateItem("TaskManager")
    TrayCreateItem("") ; Create a separator line.
Local $iRestartSensor = TrayCreateItem("RestartSensor")
    TrayCreateItem("") ; Create a separator line.
Local $iShutdown = TrayCreateItem("Shutdown")
    TrayCreateItem("") ; Create a separator line.
Local $idExit = TrayCreateItem("Exit")
    TraySetState($TRAY_ICONSTATE_SHOW) ; Show the tray menu.

While 1
    Switch TrayGetMsg()
        Case $iSteam
            ShellExecute("D:\Spiele\Steam\Steam.exe")

        Case $iMobileAuthenticator
            ShellExecute("D:\Batch Space\WindowsAutomation\MobileAuthenticator.au3")

        Case $iPUBG
            ShellExecute("steam://rungameid/578080")

        Case $iDARWIN
            ShellExecute("steam://rungameid/544920")

        Case $iFORTNITE
            Run("D:\Spiele\Epic Games\Fortnite\FortniteGame\Binaries\Win64\FortniteClient-Win64-Shipping.exe")

        Case $iStopWatch
            ShellExecute("D:\Batch Space\WindowsAutomation\StopWatch.au3")

        Case $iTimer
            ShellExecute("D:\Batch Space\Timer\Timer.bat")

        Case $iTaskManager
            ShellExecute("D:\Batch Space\TaskManager\Taskmanager.bat")

        Case $iRestartSensor
            If ProcessExists("RemotePanel.exe") Then ProcessClose("RemotePanel.exe")
            If ProcessExists("aida64.exe") Then ProcessClose("aida64.exe")
            ScreenState()
            ShellExecute("C:\Program Files (x86)\FinalWire\AIDA64 Extreme\aida64.exe","",@SW_SHOWNORMAL)
            Run("C:\Program Files (x86)\Odospace\Remote Panel\RemotePanel.exe")

        Case $iShutdown
            ShellExecute("D:\Batch Space\WindowsAutomation\Shutdown.au3")

        Case $idExit
            for $i = 1 To $dcPID[0]
            If ProcessExists($dcPID[$i]) Then ProcessClose($dcPID[$i])
        Next
            Exit

    EndSwitch
WEnd

Func SciTEClipboard()
    _sMsgBox("SciTE Clipboard", "MsgBox;_sMsgBox", "Choose a option: ", "db=1;to=7;tr=10")
    if @extended = 1 Then ClipPut('MsgBox(0, "Test", "Test")')
    if @extended = 2 Then ClipPut('_sMsgBox("Test", "Ok", "Test", "")'&@CRLF)
    Return
EndFunc

Func Notepad()
    _sMsgBox("Launch SciTE or Notepad++?", "SciTE;Notepad++", "Launch SciTE or Notepad++?", "db=1;to=10;tr=10")
        if @extended = 1 Then Run("C:\Program Files (x86)\AutoIt3\SciTE\SciTE.exe")
        if @extended = 2 Then Run("C:\Program Files (x86)\Notepad++\notepad++.exe")
EndFunc

Func SwitchSoundDevice($SoundDevice = "")
    local $NirCMD = "D:\Batch Space\tools\nircmd.exe" ; nircmd.exe path
    local $IconPath = "D:\Batch Space\ICON\" ; Icons path
    local $CurrentDevice = StringLeft(_GetCurrentSoundDevice(), 7)
    If Not IsDeclared("SoundDevice") Then
        if $CurrentDevice = "Headset" Then Local $SoundDevice = "Speaker"
        if $CurrentDevice = "Speaker" Then Local $SoundDevice = "Headset"
        Run($NirCMD & " setdefaultsounddevice " & $SoundDevice)
    EndIf
    TrayTip($SoundDevice & " active.", " ", 1, $TIP_ICONASTERISK)
    TraySetToolTip($SoundDevice & " active.")
    TraySetIcon($IconPath & $SoundDevice & ".ico")
    Local $sActualWindow = WinGetTitle("[ACTIVE]")
    If $SoundDevice = "Headset" Then
        If Not ProcessExists("ts3client_win64.exe") Then
            _sMsgBox("Headset Active, Teamspeak not.", "Yes;No", "Headset active, TeamSpeak 3 is not running.", "db=1;to=10")
            If @extended = 1 Then
                ShellExecute("C:\Program Files\TeamSpeak 3 Client\ts3client_win64.exe")
                WinWaitActive("TeamSpeak3")
            EndIf
        EndIf
    EndIf
    If ProcessExists("ts3client_win64.exe") Then
        WinActivate("TeamSpeak3")
        If $SoundDevice = "Speaker" Then Send("!b") ; Alt + b -> Mute Mic/Speaker in Teamspeak.
        If $SoundDevice = "Headset" Then Send("!m") ; Alt + m -> Unmute Mic/Speaker in Teamspeak.
    EndIf
    If WinExists($sActualWindow) Then WinActivate($sActualWindow)
EndFunc

Func AppMinMax($IsMinimized) ;==>AppMinMax function.
    If $IsMinimized = 0 Then
        $ActualWindow = WinGetTitle("[ACTIVE]")
        TraySetState($TRAY_ICONSTATE_FLASH)
        WinSetState($ActualWindow, "", @SW_MINIMIZE)
        TraySetToolTip("Minimized: " & $ActualWindow)
        $IsMinimized = 1
    else
        Local $Process = _ProcessGetName(WinGetProcess($ActualWindow))
        For $i = 1 to _FileCountLines("D:\Batch Space\WindowsAutomation\Games.txt")
        $Line = FileReadLine("D:\Batch Space\WindowsAutomation\Games.txt", $i)
        If $line = $Process Then
            If WinExists($ActualWindow) Then
                WinActivate($ActualWindow)
                WinSetState($ActualWindow, "", @SW_MAXIMIZE)
            EndIf
            ExitLoop
        EndIf
        Next
        WinActivate($ActualWindow)
        TraySetToolTip("Restored: " & $ActualWindow)
        TraySetState($TRAY_ICONSTATE_STOPFLASH)
        $IsMinimized = 0
    EndIf
EndFunc ;==>AppMinMax stop.

Func Taskkiller() ;==>Taskkiller function.
    local $Window = WinGetTitle("[ACTIVE]")
    local $Process = _ProcessGetName(WinGetProcess($Window))
    _sMsgBox("Kill " & $Process  & "?", "Yes.,No.", "Do you like to kill: " &@LF&@LF& $Window & "?", "db=1;to=1,20")
        If @extended = 1 Then ProcessClose($Process)
    If WinExists($Window) Then WinActivate($Window)
EndFunc ;==>Taskkiller stop.

Func SteamFriends() ;==>SteamFriends function.
    ShellExecute("steam://open/friends/")
    AppMinMax(0)
    WinActivate("Friends")
EndFunc ;==>SteamFriends stop.

Func AutoStart()
    TraySetToolTip("Autorun active.")
    TraySetIcon("D:\Batch Space\ICON\Autorun.ico")
    TraySetState($TRAY_ICONSTATE_FLASH)
    RunWait('regedit /s "D:\Batch Space\WindowsAutomation\REGISTRY.reg"')
    ShellExecute("C:\Program Files (x86)\Intel\Intel(R) Extreme Tuning Utility\Client\PerfTune.exe","",@SW_SHOWNORMAL)
    WinWaitActive("Intel® Extreme Tuning Utility", "", 20)
    WinActivate("Intel® Extreme Tuning Utility")
    WinClose("Intel® Extreme Tuning Utility")
    If ProcessExists("RemotePanel.exe") Then ProcessClose("RemotePanel.exe")
    If ProcessExists("aida64.exe") Then ProcessClose("aida64.exe")
    ScreenState()
    ShellExecute("C:\Program Files (x86)\FinalWire\AIDA64 Extreme\aida64.exe","",@SW_SHOWNORMAL)
    Run("C:\Program Files (x86)\Odospace\Remote Panel\RemotePanel.exe")
    Run("G:\Programme\Tools\W10Privacy\W10Privacy.exe /s 1")
    BatteryLevel()
    TraySetState($TRAY_ICONSTATE_STOPFLASH)
EndFunc

Func ScreenState()
    FileChangeDir("C:\Program Files (x86)\Odospace\Remote Panel\adb")
    If ProcessExists("adb.exe") Then ProcessClose("adb.exe")
    Local $Odospace = StringInStr(_RunCmd('adb -s 3200d994ae6f9000 shell dumpsys activity activities | find "mFocusedActivity:"'), "com.odospace.remotepanel")
    If $Odospace <> 0 Then RunWait(@ComSpec & ' /c ' & "adb -s 3200d994ae6f9000 shell am force-stop com.odospace.remotepanel", @TempDir, @SW_HIDE)
    RunWait(@ComSpec & ' /c ' & "adb -s 3200d994ae6f9000 shell monkey -p com.odospace.remotepanel -c android.intent.category.LAUNCHER 1", @TempDir, @SW_HIDE)
    RunWait(@ComSpec & ' /c ' & "adb -s 3200d994ae6f9000 shell input keyevent KEYCODE_WAKEUP", @TempDir, @SW_HIDE)
EndFunc

Func BatteryLevel()
    FileChangeDir("C:\Program Files (x86)\Odospace\Remote Panel\adb")
    If ProcessExists("adb.exe") Then ProcessClose("adb.exe")
    Local $sBatteryLevel = StringTrimLeft(_RunCmd('adb -s 3200d994ae6f9000 shell dumpsys power | find "mBatteryLevel="'), 14)
    If $sBatteryLevel < 10 Then
        MsgBox(0, "Warning!", "Battery Level from Sensor Tablet is at: " & $sBatteryLevel & "%" & @CRLF & @CRLF & "Press ok to shutdown Tablet.")
        RunWait(@ComSpec & ' /c ' & "adb -s 3200d994ae6f9000 shell input keyevent KEYCODE_SLEEP", @TempDir, @SW_HIDE)
    Endif
    TrayTip("Tablet Battery Level is at: " & $sBatteryLevel & " %.", " ", 1, $TIP_ICONASTERISK)
EndFunc

Func _RunCmd($sCommand)
 If StringLeft($sCommand, 1) = " " Then $sCommand = " " & $sCommand
 Local $nPid = Run (@Comspec & " /c" & $sCommand, "", @SW_Hide, 8), $sRet = ""
 If @Error then Return "ERROR:" & @ERROR
 ProcessWait ($nPid)
 While 1
    $sRet &= StdoutRead($nPID)
    If @error Or (Not ProcessExists($nPid)) Then ExitLoop
 WEnd
 Return StringStripWS($sRet, 3)
EndFunc ; ==> _RunCmd

 

Link to comment
Share on other sites

Hi, it's kinda hard to test this when i don't have:

#include "ScalingMessageBox.au3"
#include "_GetCurrentSoundDevice.au3"
#include <_MuteActiveWindow.au3>

But anyway, anytime you have something like RunWait, there's a possibility the script stops there if there's a problem.

Spoiler

Renamer - Rename files and folders, remove portions of text from the filename etc.

GPO Tool - Export/Import Group policy settings.

MirrorDir - Synchronize/Backup/Mirror Folders

BeatsPlayer - Music player.

Params Tool - Right click an exe to see it's parameters or execute them.

String Trigger - Triggers pasting text or applications or internet links on specific strings.

Inconspicuous - Hide files in plain sight, not fully encrypted.

Regedit Control - Registry browsing history, quickly jump into any saved key.

Time4Shutdown - Write the time for shutdown in minutes.

Power Profiles Tool - Set a profile as active, delete, duplicate, export and import.

Finished Task Shutdown - Shuts down pc when specified window/Wndl/process closes.

NetworkSpeedShutdown - Shuts down pc if download speed goes under "X" Kb/s.

IUIAutomation - Topic with framework and examples

Au3Record.exe

Link to comment
Share on other sites

7 hours ago, careca said:

Hi, it's kinda hard to test this when i don't have:

#include "ScalingMessageBox.au3"
#include "_GetCurrentSoundDevice.au3"
#include <_MuteActiveWindow.au3>

But anyway, anytime you have something like RunWait, there's a possibility the script stops there if there's a problem.

I dont think it will run either un your system.

I think u get the point im searching for, how to prevent starting a new function if the other dont complete?

_GetCurrentSoundDevice.au3

_MuteActiveWindow.au3

ScalingMessageBox.au3

Link to comment
Share on other sites

No real need to quote what I just wrote. Anyway in order to do that just use a variable and some checks.

Spoiler

Renamer - Rename files and folders, remove portions of text from the filename etc.

GPO Tool - Export/Import Group policy settings.

MirrorDir - Synchronize/Backup/Mirror Folders

BeatsPlayer - Music player.

Params Tool - Right click an exe to see it's parameters or execute them.

String Trigger - Triggers pasting text or applications or internet links on specific strings.

Inconspicuous - Hide files in plain sight, not fully encrypted.

Regedit Control - Registry browsing history, quickly jump into any saved key.

Time4Shutdown - Write the time for shutdown in minutes.

Power Profiles Tool - Set a profile as active, delete, duplicate, export and import.

Finished Task Shutdown - Shuts down pc when specified window/Wndl/process closes.

NetworkSpeedShutdown - Shuts down pc if download speed goes under "X" Kb/s.

IUIAutomation - Topic with framework and examples

Au3Record.exe

Link to comment
Share on other sites

2 hours ago, xtcislove said:

how to prevent starting a new function if the other dont complete?

Hi xtcislove,

Maybe what I use in a script could help you : as soon as you enter a hotkey function, you deactivate all other hotkey functions and reactivate them before leaving the function, like this :

HotKey_Activate()   

; main script here

Func _0()
    HotKey_Deactivate()
    ; your code for key 0 here
    HotKey_Activate()
EndFunc     ; ==> _0
    
Func HotKey_Activate()
   HotKeySet("{NUMPAD0}", "_0") 
   HotKeySet("{NUMPAD1}", "_1")
   HotKeySet("{NUMPAD2}", "_2")
   HotKeySet("{NUMPAD3}", "_3")
   HotKeySet("{NUMPAD4}", "_4")
   HotKeySet("{NUMPAD5}", "_5")
   HotKeySet("{NUMPAD6}", "_6")
   HotKeySet("{NUMPAD7}", "_7")
   HotKeySet("{NUMPAD8}", "_8")
   HotKeySet("{NUMPAD9}", "_9")
   HotKeySet("{RIGHT}", "Fl_droite")
   HotKeySet("{LEFT}", "Fl_gauche")
   HotKeySet("{SPACE}", "Pause")
   HotKeySet("{ESC}", "Terminate")
EndFunc     ; ==> HotKey_Activate

Func HotKey_Deactivate()
   HotKeySet("{NUMPAD0}")
   HotKeySet("{NUMPAD1}")
   HotKeySet("{NUMPAD2}")
   HotKeySet("{NUMPAD3}")
   HotKeySet("{NUMPAD4}")
   HotKeySet("{NUMPAD5}")
   HotKeySet("{NUMPAD6}")
   HotKeySet("{NUMPAD7}")
   HotKeySet("{NUMPAD8}")
   HotKeySet("{NUMPAD9}")
   HotKeySet("{RIGHT}")
   HotKeySet("{LEFT}")
   HotKeySet("{SPACE}")
   HotKeySet("{ESC}")
EndFunc     ; ==> HotKey_Deactivate

Hope it will help you :)

Link to comment
Share on other sites

1 hour ago, pixelsearch said:

Hi xtcislove,

Maybe what I use in a script could help you : as soon as you enter a hotkey function, you deactivate all other hotkey functions and reactivate them before leaving the function, like this :

Hope it will help you :)

SetHotKey(1)

Func SetHotKey($iState)
    If $iState = 0 Then
        HotKeySet("+!s")
        HotKeySet("+!k")
        HotKeySet("+!t")
        HotKeySet("+!f")
        HotKeySet("+!n")
        HotKeySet("+!m")
        HotKeySet("+!c")
    ElseIf $iState = 1 Then
        HotKeySet("+!s", "SwitchSoundDevice") ; Shift-Alt-t. - Hotkey to switch between devices.
        HotKeySet("+!k", "AppMinMax") ; Shift-Alt-k. - Hotkey to minimize/maximize current app.
        HotKeySet("+!t", "Taskkiller") ; Shift-Alt-t. - Hotkey to kill current app.
        HotKeySet("+!f", "SteamFriends") ; Shift-Alt-f. - Hotkey to open Steam Friends.
        HotKeySet("+!n", "Notepad") ; Shift-Alt-N. - Hotkey for Notepad Function.
        HotKeySet("+!m", "_MuteActiveWindow") ; Shift-Alt-M. - Hotkey to mute active window sound.
        HotKeySet("+!c", "SciTEClipboard") ; Shift-Alt-M. - Hotkey to mute active window sound.
        TrayMenu()
    EndIf
EndFunc

This helped :)

 

Link to comment
Share on other sites

Local $var = 0

Func Test()
    If $var = 0 Then
        $var =1
        ConsoleWrite('Test - '&@MSEC&@CRLF)
        ;whatever
        $var =0
    EndIf
EndFunc

In theory, if all functions are constructed like this, only one should run at a time, simply because the var is 1 during run, and only becomes 0 after it's done, and only then the other funcs may run.

Spoiler

Renamer - Rename files and folders, remove portions of text from the filename etc.

GPO Tool - Export/Import Group policy settings.

MirrorDir - Synchronize/Backup/Mirror Folders

BeatsPlayer - Music player.

Params Tool - Right click an exe to see it's parameters or execute them.

String Trigger - Triggers pasting text or applications or internet links on specific strings.

Inconspicuous - Hide files in plain sight, not fully encrypted.

Regedit Control - Registry browsing history, quickly jump into any saved key.

Time4Shutdown - Write the time for shutdown in minutes.

Power Profiles Tool - Set a profile as active, delete, duplicate, export and import.

Finished Task Shutdown - Shuts down pc when specified window/Wndl/process closes.

NetworkSpeedShutdown - Shuts down pc if download speed goes under "X" Kb/s.

IUIAutomation - Topic with framework and examples

Au3Record.exe

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

×
×
  • Create New...