autoit-scripts – Rev 1

Subversion Repositories:
Rev:
#NoTrayIcon
#Region ;**** Directives created by AutoIt3Wrapper_GUI ****
#AutoIt3Wrapper_Icon=favicon.ico
#AutoIt3Wrapper_Outfile=Release\x86\AutoRun.exe
#AutoIt3Wrapper_Outfile_x64=Release\x64\AutoRun_x64.exe
#AutoIt3Wrapper_Compression=0
#AutoIt3Wrapper_Res_Comment=Hold shift key down in order to simulate autorun for games that do not have an autorun feature.
#AutoIt3Wrapper_Res_Description=Hold shift key down in order to simulate autorun for games that do not have an autorun feature.
#AutoIt3Wrapper_Res_Fileversion=1.0.0.7
#AutoIt3Wrapper_Res_Fileversion_AutoIncrement=y
#AutoIt3Wrapper_Res_Fileversion_First_Increment=y
#AutoIt3Wrapper_Res_ProductName=AutoRun
#AutoIt3Wrapper_Res_ProductVersion=1.0
#AutoIt3Wrapper_Res_CompanyName=Wizardry and Steamworks
#AutoIt3Wrapper_Res_LegalCopyright=Copyright © 2018 Wizardry and Steamworks
#AutoIt3Wrapper_Res_requestedExecutionLevel=asInvoker
#AutoIt3Wrapper_Res_Field=Made By|Wizardry and Steamworks
#AutoIt3Wrapper_Res_Field=Email|office@grimore.org
#AutoIt3Wrapper_Res_Field=AutoIt Version|%AutoItVer%
#AutoIt3Wrapper_Res_Field=Compile Date|%date% %time%
#AutoIt3Wrapper_AU3Check_Stop_OnWarning=y
#AutoIt3Wrapper_AU3Check_Parameters=-q -d -w 1 -w 2 -w 3 -w 4 -w 5 -w 6 -w 7
#AutoIt3Wrapper_Run_After=for %I in ("%in%" "directives.au3") do copy %I "C:\Program Files (x86)\autoit3\SciTE\AutoIt3Wrapper"
#AutoIt3Wrapper_Run_Tidy=y
#Tidy_Parameters=/sort_funcs /reel
#AutoIt3Wrapper_Run_Au3Stripper=y
#Au3Stripper_Parameters=/debug
#AutoIt3Wrapper_Versioning=v
#AutoIt3Wrapper_Versioning_Parameters=/Comments %fileversionnew%
#EndRegion ;**** Directives created by AutoIt3Wrapper_GUI ****

; Copyright 2018 Wizardry and Steamworks - MIT LICENSE
;
; Permission is hereby granted, free of charge, to any person obtaining a
; copy of this software and associated documentation files (the Software),
; to deal in the Software without restriction, including without
; limitation the rights to use, copy, modify, merge, publish, distribute,
; sublicense, and/or sell copies of the Software, and to permit persons to
; whom the Software is furnished to do so, subject to the following
; conditions:
;
; The above copyright notice and this permission notice shall be included
; in all copies or substantial portions of the Software.
;
; THE SOFTWARE IS PROVIDED AS IS, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
; IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
; FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
; THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR
; OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
; ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
; OTHER DEALINGS IN THE SOFTWARE.

Global Const $VERSION = "1.0.0.7"
#AutoIt3Wrapper_Testing=n
#pragma compile(AutoItExecuteAllowed, true)
#AutoIt3Wrapper_ShowProgress=n

#include <WinAPISys.au3>
#include <WinAPIFiles.au3>
#include <WinAPIvkeysConstants.au3>
#include <File.au3>
#include <FileConstants.au3>
#include <MsgBoxConstants.au3>
#include <AutoItConstants.au3>
#include <StringConstants.au3>
; Required for the $TRAY_CHECKED and $TRAY_ICONSTATE_SHOW constants.
#include <TrayConstants.au3>
; Base64 encoder / decoder by J2TEAM (https://github.com/J2TEAM)
#include "Base64.au3"

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;                             INTERNALS                                ;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;                             MAIN LOOP                                ;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

; Setup termination handler.
OnAutoItExitRegister("Terminate")

; Setup tray icon menu.
Opt("TrayMenuMode", 3)
Opt("TrayOnEventMode", 1)
Opt("SendCapslockMode", 0)

TrayCreateItem("On", -1, -1, $TRAY_ITEM_RADIO)
TrayItemSetState(-1, $TRAY_CHECKED)
TrayItemSetOnEvent(-1, "TrayMenuOn")
TrayCreateItem("Off", -1, -1, $TRAY_ITEM_RADIO)
TrayItemSetOnEvent(-1, "TrayMenuOff")
TrayCreateItem("")
TrayCreateItem("About")
TrayItemSetOnEvent(-1, "TrayMenuAbout")
TrayCreateItem("Exit", -1, -1)
TrayItemSetOnEvent(-1, "TrayMenuExit")

; -5 for EXE
TraySetIcon(@ScriptFullPath, -5)
TraySetState($TRAY_ICONSTATE_SHOW)

Global $capsState = 0, $scriptEnabled = 1

; Run main event loop.
While 1
        If $scriptEnabled == 1 Then
                ToggleAutoRun()
        EndIf
        Sleep(100)
WEnd

Func _GetCaps()
        Local $aOnOff[2] = ['OFF', 'ON']
        Return $aOnOff[BitAND(_WinAPI_GetKeyState($VK_CAPITAL), 1)]
EndFunc   ;==>_GetCaps

; Function definitions

Func Terminate()
        ConsoleWrite("Terminating..." & @CRLF)
        Send("{LSHIFT UP}")
EndFunc   ;==>Terminate

Func ToggleAutoRun()
        Switch _GetCaps()
                Case "ON"
                        If $capsState == 0 Then
                                ConsoleWrite("Activating Auto Run" & @CRLF)
                                Send("{LSHIFT DOWN}")
                                $capsState = 1
                        EndIf
                Case "OFF"
                        If $capsState == 1 Then
                                ConsoleWrite("Deactivating Auto Run." & @CRLF)
                                Send("{LSHIFT UP}")
                                $capsState = 0
                        EndIf
        EndSwitch
EndFunc   ;==>ToggleAutoRun

Func TrayMenuAbout()
        MsgBox($MB_SYSTEMMODAL, "", "AutoRun ~ Hold down shift button." & @CRLF & @CRLF & _
                        "Version: " & FileGetVersion(@ScriptFullPath) & @CRLF & _
                        "Install Path: " & StringLeft(@AutoItExe, StringInStr(@AutoItExe, "\", $STR_NOCASESENSEBASIC, -1) - 1))
EndFunc   ;==>TrayMenuAbout

Func TrayMenuExit()
        Exit
EndFunc   ;==>TrayMenuExit

Func TrayMenuOff()
        $scriptEnabled = 0
        If $capsState == 1 Then
                Send("{LSHIFT UP}")
        EndIf
EndFunc   ;==>TrayMenuOff

Func TrayMenuOn()
        $scriptEnabled = 1
EndFunc   ;==>TrayMenuOn