Jump to content

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

 

Share this post


Link to post
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

Share this post


Link to post
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

Share this post


Link to post
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

Share this post


Link to post
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 :)

Share this post


Link to post
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 :)

 

Share this post


Link to post
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

Share this post


Link to post
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

  • Recently Browsing   0 members

    No registered users viewing this page.

  • Similar Content

    • By MONaH-Rasta
      Opt('TrayAutoPause', 0) $iTray1 = TrayCreateItem('Tray 1') TrayItemSetState(-1, 1) TrayCreateItem('') $iTrayMenu1 = TrayCreateMenu('Tray Menu 1') $iTray2 = TrayCreateItem('Tray 2', $iTrayMenu1, -1, 1) TrayItemSetState(-1, 1) $iTray3 = TrayCreateItem('Tray 3', $iTrayMenu1, -1, 1) $iTray4 = TrayCreateItem('Tray 4', $iTrayMenu1, -1, 1) TrayCreateItem('') $iTrayMenu2= TrayCreateMenu('Tray Menu 2') $iTray5 = TrayCreateItem('Tray 5', $iTrayMenu2, -1, 1) TrayItemSetState(-1, 1) $iTray6 = TrayCreateItem('Tray 6', $iTrayMenu2, -1, 1) $iTray7 = TrayCreateItem('Tray 7', $iTrayMenu2, -1, 1) TrayCreateItem('') $iTray8 = TrayCreateItem('Tray 8') $iTray9 = TrayCreateItem('Tray 9') $iTray10 = TrayCreateItem('Tray 10') TrayItemSetState(-1, 1) While True Sleep(1000*5) WEnd When I click on Tray 3 / Tray 4 / Tray 6 / Tray 7 nothing happens. Only Tray 2 and Tray 5 stay checked.
      I have tried setting 
      Opt("TrayMenuMode", 8) In this case radio menuitems act like normal menuitems only looks different.
      I'm using AutoIt v3.3.14.5.
      Tested on Windows 10 LTSC 2019 (1809) x64 version: 10.0.17763 build 17763.475 and Windows Server 2008 R2.
      Tried run script x64 and x86 same result.
      Is this kind a bug or something?
    • By amin84
      Hello,
      I'm trying to write a hotkey program and I know exactly how to do it but it will be hard coded and the user won't be able to edit it.
      HotKeySet("{ESC}", "HotKeyPressed") HotKeySet("^!d", "HotKeyPressed") HotKeySet("^+x", "HotKeyPressed") While 1 Sleep(500) WEnd Func HotKeyPressed() Switch @HotKeyPressed Case "{ESC}" Exit Case "^!d" ShellExecute("D:\Docs") Case "^+x" ShellExecute("D:\Docs\My Portables\Burner\AnyBurn\AnyBurn.exe") EndSwitch EndFunc I want the program to read a file that has hotkeys on odd lines and paths on even lines but I don't see how the program will load into itself.
      Is it even possible?
      Thanks.
    • By kokoilie
      I'm making a program that has a combo control in a gui and back in win7 when the window was focused the scroll wheel could be used to scroll through it's contents, now i'm using win10 and i have to put the mouse on that control to scroll up and down.
      Since now the scroll wheel works depending on where the mouse is, is there a way to make it no matter where on the gui the pointer is?
      Also if the only way to do it is some complex hotkey functions will it work with pressing space to toggle a checkbox?
      If you need to see what i have so far let me know and i'll copy it here.
    • By Guy_
      I'd be happy with help, even for problem (1) alone, so don't be overwhelmed...
      Rusty and frustrated with some weird stuff in my program for well over 2 years, I've finally made a reproducer... (I'm using v3.3.14.1 here)
      In this forum, I picked up some code to detect a Mouse Right-click (see URL below). I have no idea if that code is solid or dodgy...
      In my program I test for the combo of Shift + Right-click, which will then automatically copy the URL of an underlying html link and do stuff with it (here simply replaced with a BEEP).
      In the reproducer, when doing Shift + R-click anywhere, this should initially BEEP (if your sound is on), unless you enable the TrayMenu...
      Problems that have come up so far ...
      (1) [SOLVED with help of 3rd post] If you enable the line creating the _Example_TrayMenu(), that menu will work but my Shift + R-click feature seems sabotaged by it for some reason...?
      (2) [I pray this might be solved by (1), cause this one may be hard to get a clue on...]
      If I set everything [no TrayMenu] so I can use the Shift + R-click detection, another problem is that this feature often gets disabled somehow — usually between 5 to 120 mins. Occasionally, it still works the following morning. Still have I been unable to get a clue to what might sabotage it. It might be a specific thing me or my PC is doing, or might it be a buffer that is corrupting by the use of the detection code? (I'm pretty sure I'm also getting this without pausing/unpausing my program, but I'll retest) (there is a chance this may not happen in the reproducer and only in my full program; I'll try and test for that)
      (3) To hopefully prevent (2) — and since I usually pause the utility quite often — I hoped that at the same time correctly stopping and restarting this detection system might mostly prevent the problem, or at least make it easy for me to reboot the functionality by pausing/unpausing. I asked if I was doing that right more than a year ago, but possibly in a time that many took their holiday, so never heard back. That question (and the original detection code) is here (I guess it needs a reproducer too, and I may make that tomorrow...) : 
      If (1) could get solved, I'd be very happy and could retest for (2) a while. (3) is of course also very welcome, cause it might be the 'easy' workaround for (2), or another reason stuff might get corrupted (although I'm currently probably not pausing/unpausing the detection system, cause how I do it crashes AutoIt; see other topic).
      Thank You for having a look! 
      #Region #AutoIt3Wrapper_UseX64=n #EndRegion #include <Misc.au3> #include <WinAPI.au3> #include <WindowsConstants.au3> #include <MsgBoxConstants.au3> #include <TrayConstants.au3> Opt("TrayMenuMode", 3) Local $hDLL = DllOpen("user32.dll") ;~ _Example_TrayMenu() ; When enabled, the Shift + R-click detection won't work. Why? ; mouse R-click detection code from www.autoitscript.com/forum/topic/119856-detect-fast-mouse-click Global Const $HC_ACTION = 0 Global $hStub_MouseProc = DllCallbackRegister("_MouseProc", "long", "int;wparam;lparam") Global $hmod = _WinAPI_GetModuleHandle(0) Global $hHook = _WinAPI_SetWindowsHookEx($WH_MOUSE_LL, DllCallbackGetPtr($hStub_MouseProc), $hmod) Global $iMseDwn = 0 Func _MouseProc($nCode, $wParam, $lParam) If $nCode < 0 Then Return _WinAPI_CallNextHookEx($hHook, $nCode, $wParam, $lParam) EndIf If $nCode = $HC_ACTION Then Switch $wParam Case $WM_RBUTTONDOWN $iMseDwn = 3 ; assigned code for a Mouse R-click EndSwitch EndIf Return _WinAPI_CallNextHookEx($hHook, $nCode, $wParam, $lParam) EndFunc While 1 ; MAIN LOOP Switch $iMseDwn Case 3 ; Mouse Right was clicked MouseUp($MOUSE_CLICK_RIGHT) ; 'unclick' it $iMseDwn = 0 ; reset var If _isPressed("10", $hDLL) Then ; is Shift held down as well? _Mouse_R_click(10) ; (10 = Shift key) call BEEP Func EndIf EndSwitch Sleep(50) WEnd Func _Mouse_R_click($_modKey) ; called from MAIN LOOP if Shift was held down before R-click If $_modKey = 10 Then ;~ MsgBox(0,"", "You performed Shift + R-click") Beep(300,30) EndIf EndFunc Func _Example_TrayMenu() ; example from AutoIt Help on TrayCreateMenu Local $iSettings = TrayCreateMenu("Settings") Local $iDisplay = TrayCreateItem("Display", $iSettings) Local $iPrinter = TrayCreateItem("Printer", $iSettings) TrayCreateItem("") Local $idAbout = TrayCreateItem("About") TrayCreateItem("") Local $idExit = TrayCreateItem("Exit") TraySetState($TRAY_ICONSTATE_SHOW) While 1 Switch TrayGetMsg() Case $idAbout MsgBox($MB_SYSTEMMODAL, "", "AutoIt tray menu example." & @CRLF & @CRLF & _ "Version: " & @AutoItVersion & @CRLF & _ "Install Path: " & StringLeft(@AutoItExe, StringInStr(@AutoItExe, "\", 0, -1) - 1)) Case $iDisplay, $iPrinter MsgBox($MB_SYSTEMMODAL, "", "A sub menu item was selected from the tray menu.") Case $idExit ExitLoop EndSwitch WEnd EndFunc  
       
    • By Guy_
      Included is a working piece of code to enlarge the handy Move / Copy dialog windows in FastStone Image Viewer, and default to the Favorites tab
      I am usually using a main program with hotkeys.
      Therefore the While 1 ... WEnd loop.
      I only recently made the beginning of a TrayMenu, but I have not come across how to ideally incorporate this with the While 1 ... loop yet...
      If I only include _exampleTrayMenu() in the loop, that works.
      If I only include the FastStone test without _exampleTrayMenu(), that works.
      If I include both in the loop, like in the example, the FastStone code doesn't enlarge the window and the TrayMenu often jumps into Pause / flashing.
      1) Where to put _exampleTrayMenu() code so all combines...?
      2) How to most efficiently combine multiple window detection cases in the future?
      3) ...or can you run more than one AutoIt .exe and would you advise that?
      For me too, it would be clearer if I had all window detection code and small stuff in a 2nd .exe.

       
      #include <MsgBoxConstants.au3> #include <TrayConstants.au3> Opt("WinTitleMatchMode", 2) ; MAIN program loop While 1 If WinActive("[CLASS:TCopyMoveFolder]") Then _FastStoneImgViewer() Else _exampleTrayMenu() Sleep(100) EndIf WEnd ; Detect opening of both Copy & Move windows in Faststone viewer, enlarge them and click 'Favorites' tab Func _FastStoneImgViewer()     ; if WinActive(" to Folder") (when Copy or Move window appears)     If WinActive( "[CLASS:TCopyMoveFolder]" ) Then         Local $hWnd = WinGetHandle("[CLASS:TCopyMoveFolder]")         ; click once on tab 'Favorites'         ControlClick( $hWnd, "", "[CLASS:TbsSkinPageControl; INSTANCE:1]", "left", 1, 70, 10 )         ; enlarge window         WinMove($hWnd, "", Default, 60, 900, 1060)         ; move buttons down         ; BUTTON Clear History List         ControlMove($hWnd, "", "[CLASS:TbsSkinButton; INSTANCE:1]", Default, 990)         ; BUTTON         ControlMove($hWnd, "", "[CLASS:TbsSkinButton; INSTANCE:2]", Default, 990)         ; BUTTON         ControlMove($hWnd, "", "[CLASS:TbsSkinButton; INSTANCE:3]", Default, 990)         ; BUTTON         ControlMove($hWnd, "", "[CLASS:TbsSkinButton; INSTANCE:4]", Default, 990)         ; ENLARGE the Inside Window         ControlMove($hWnd, "", "[CLASS:TbsSkinPageControl; INSTANCE:1]", Default, Default, 862, 910)         ; ensure focus is back to inside window and previously selected item (so 'select by keypress' will work)         ControlFocus( $hWnd, "", "[CLASS:TListView; INSTANCE:1]" )         WinWaitNotActive($hWnd)     EndIf EndFunc ; traymenu example from manual Func _exampleTrayMenu() Local $iSettings = TrayCreateMenu("Settings") ; Create a tray menu sub menu with two sub items. Local $iDisplay = TrayCreateItem("Display", $iSettings) Local $iPrinter = TrayCreateItem("Printer", $iSettings) TrayCreateItem("") ; Create a separator line. Local $idAbout = TrayCreateItem("About") TrayCreateItem("") ; Create a separator line. Local $idExit = TrayCreateItem("Exit") TraySetState($TRAY_ICONSTATE_SHOW) ; Show the tray menu. While 1 Switch TrayGetMsg() Case $idAbout ; Display a message box about the AutoIt version and installation path of the AutoIt executable. MsgBox($MB_SYSTEMMODAL, "", "AutoIt tray menu example." & @CRLF & @CRLF & _ "Version: " & @AutoItVersion & @CRLF & _ "Install Path: " & StringLeft(@AutoItExe, StringInStr(@AutoItExe, "\", 0, -1) - 1)) ; Find the folder of a full path. Case $iDisplay, $iPrinter MsgBox($MB_SYSTEMMODAL, "", "A sub menu item was selected from the tray menu.") Case $idExit ; Exit the loop. ExitLoop EndSwitch WEnd EndFunc
×
×
  • Create New...