Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*
- * * * Compile_AHK SETTINGS BEGIN * * *
- [AHK2EXE]
- Exe_File=%In_Dir%\XBMCLauncher.exe
- Created_Date=1
- [VERSION]
- Set_Version_Info=1
- Company_Name=baijuxavior@gmail.com
- File_Description=Customize XBMC Startup
- File_Version=3.1.0.0
- Inc_File_Version=0
- Internal_Name=XBMCLauncher
- Legal_Copyright=C@P Baiju Xavior
- Original_Filename=XBMCLauncher
- Product_Name=XBMCLauncher
- Product_Version=3.1.0.0
- [ICONS]
- Icon_1=%In_Dir%\XBMCLauncher.ico
- Icon_2=%In_Dir%\XBMCLauncher.ico
- * * * Compile_AHK SETTINGS END * * *
- */
- #NoEnv ; Recommended for performance and compatibility with future AutoHotkey releases.
- #Warn ; Recommended for catching common errors.
- #SingleInstance ignore ; create only one running instance
- #Include tf.ahk ; include file manipulation
- SendMode Input ; Recommended for new scripts due to its superior speed and reliability.
- SetWorkingDir %A_ScriptDir% ; Ensures a consistent starting directory.
- DllCall("CreateMutex", "uint", 0, "int", false, "str", "xbmc_launcher_mutex") ; create a mutex to find whether the application is already running while installation.
- ProgFiles32() ;get 32 bit program files folder
- {
- EnvGet, ProgFiles32, ProgramFiles(x86)
- if ProgFiles32 = ; Probably not on a 64-bit system.
- EnvGet, ProgFiles32, ProgramFiles
- Return %ProgFiles32%
- }
- ; >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> GLOBAL VARIABLES DECLARATION AND DEFAULT VALUES <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
- Global ProgFiles := ProgFiles32() ;Program files path
- global SettingsPath := A_AppData . "\XBMCLauncher\Settings.ini"
- global XBMCPath := ProgFiles . "\xbmc\xbmc.exe"
- global XBMConiMONPath := ProgFiles . "\xbmc-on-imon-v0.1.9.5\xbmconimon.exe"
- global iMONPath := ProgFiles . "\SoundGraph\iMON\iMON.exe"
- global version = 3.1
- global FocusDelay := GetSettings("Delay", 10000)
- global FocusOnce := GetSettings("FocusOnce", 0)
- global DisableFocusTemporarily = 0
- global FocussedOnce = 0
- global FocusCount = 0
- global WinKeySent = 0
- global ForceClose := GetSettings("ForceClose", 0)
- global StartExplorer := GetSettings("StartExplorer", 1)
- global PressWinKey := GetSettings("PressWinKey", 1)
- global ShowShutdownMenu := GetSettings("Shutdown", 0)
- global ShutdownAction := GetSettings("Shutdown", "u")
- global ShutdownButtonClicked := GetSettings("ShutdownButtonClicked", 0)
- global EditDialogButton := GetSettings("EditDialogButtonMenu", 0)
- global ExternalPlayerPath := GetSettings("ExternalPlayer_Path", ProgFiles . "\ArcSoft\TotalMedia Theatre 5\uMCEPlayer5.exe")
- global ExternalPlayerRunning = 0
- global Suspending = 0
- global StartupDelay := GetSettings("StartupDelay", 0)
- global StartAtWinLogon := GetSettings("StartAtWinLogon", 1)
- global StartAtWinResume := GetSettings("StartAtWinResume", 1)
- global BreakFocus = 0 ; break focus while setting xbmclauncher settings
- global ShellName
- XBMCPath := GetSettings("XBMC_Path", XBMCPath)
- XBMConiMONPath := GetSettings("XBMConiMON_Path", XBMConiMONPath)
- iMONPath := GetSettings("iMON_Path", iMONPath)
- Global App1 := GetSettings("App1_Path", " ")
- Global App2 := GetSettings("App2_Path", " ")
- Global App3 := GetSettings("App3_Path", " ")
- global StartApps := GetSettings("StartApps", 0)
- global PreventFocusApps := GetSettings("PreventFocusApps", 0)
- Global App4 := GetSettings("App4_Path", " ")
- Global App5 := GetSettings("App5_Path", " ")
- Global App6 := GetSettings("App6_Path", " ")
- global StartApps_1 := GetSettings("StartApps_1", 0)
- global PreventFocusApps_1 := GetSettings("PreventFocusApps_1", 0)
- ; >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> CREATE MENU ITEMS <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
- RegRead, ShellName, HKCU, Software\Microsoft\Windows NT\CurrentVersion\Winlogon, Shell
- SplitPath, ShellName, ShellName
- If ShellName != XBMCLauncher.exe
- ShellName = Explorer.exe
- fdelay := FocusDelay // 1000 ; variable to show menu name with delay
- sdelay := StartupDelay // 1000
- IfExist, %A_WorkingDir%\XBMCLauncher.ico
- Menu, Tray, Icon, %A_WorkingDir%\XBMCLauncher.ico ; create tray icon.
- Menu, Tray, add, Start XBMC [Win+Alt+Enter], MenuStartXBMCHandler
- Menu, Tray, add, Start XBMC When Windows Starts, MenuStartXBMCAtWindowsLogonHandler
- Menu, Tray, add, Start XBMC When Windows Resumes from Sleep, MenuStartXBMCAtWindowsResumeHandler
- Menu, Tray, UnCheck, Start XBMC When Windows Starts
- Menu, Tray, UnCheck, Start XBMC When Windows Resumes from Sleep
- Menu, Tray, add, Change Startup Delay [%sdelay% sec], MenuSetStartupDelayHandler
- Menu, Tray, add ;add separator
- Menu, Tray, add, Change Focus Delay [%fdelay% sec], MenuSetFocusDelayHandler
- Menu, Tray, add, Disable Focus Temporarily [Win+F9], MenuDisableFocusHandler
- Menu, Tray, UnCheck, Disable Focus Temporarily [Win+F9]
- Menu, Tray, add, Check Focus Only Once, MenuCheckFocusOnceHandler
- Menu, Tray, UnCheck, Check Focus Only Once
- Menu, Tray, add ;add separator
- if (ShowShutdownMenu <> 0)
- Menu, Tray, add, Set Shutdown Action (for confluence skin only), MenuSetShutdownActionHandler
- Menu, Tray, add, Force Close XBMC on Suspend, MenuForceCloseXBMCHandler
- Menu, Tray, UnCheck, Force Close XBMC on Suspend
- Menu, Tray, add, Start Windows Explorer when XBMC is closed, MenuStartExplorerHandler
- Menu, Tray, UnCheck, Start Windows Explorer when XBMC is closed
- Menu, Tray, add, Send Windows Key when XBMC is closed, MenuPressWinKeyHandler
- Menu, Tray, UnCheck, Send Windows Key when XBMC is closed
- Menu, Tray, add ;add separator
- shell := RTrim(ShellName, "`.exe")
- Menu, Tray, add, Change Windows Shell [Current Shell - %shell%], MenuChangeShellHandler
- Menu, Tray, add ;add separator
- Menu, Tray, add, Set XBMC Path, MenuSetXBMCPathHandler
- Menu, Tray, add, Set XBMConiMON Path, MenuSetXBMConiMONPathHandler
- Menu, Tray, add, Set iMON Path, MenuSetiMONPathHandler
- Menu, Tray, add, Set External Player Path (for focus disable), MenuSetExternalPlayerHandler
- Menu, Tray, add ;add separator
- SplitPath, App1, AppName
- if (AppName = "")
- AppName = Not Set
- Menu, Tray, add, Set Application 1 - %AppName%, MenuSetApp1Handler
- SplitPath, App2, AppName
- if (AppName = "")
- AppName = Not Set
- Menu, Tray, add, Set Application 2 - %AppName%, MenuSetApp2Handler
- SplitPath, App3, AppName
- if (AppName = "")
- AppName = Not Set
- Menu, Tray, add, Set Application 3 - %AppName%, MenuSetApp3Handler
- Menu, Tray, add, Start First Group Applications with XBMC Launcher, MenuStartAppsHandler
- Menu, Tray, UnCheck, Start First Group Applications with XBMC Launcher
- Menu, Tray, add, First Group Apps Prevent Focus, MenuAppsPreventFocusHandler
- Menu, Tray, UnCheck, First Group Apps Prevent Focus
- Menu, Tray, add ;add separator
- SplitPath, App4, AppName
- if (AppName = "")
- AppName = Not Set
- Menu, Tray, add, Set Application 4 - %AppName%, MenuSetApp4Handler
- SplitPath, App5, AppName
- if (AppName = "")
- AppName = Not Set
- Menu, Tray, add, Set Application 5 - %AppName%, MenuSetApp5Handler
- SplitPath, App6, AppName
- if (AppName = "")
- AppName = Not Set
- Menu, Tray, add, Set Application 6 - %AppName%, MenuSetApp6Handler
- Menu, Tray, add, Start Second Group Applications with XBMC Launcher, MenuStartAppsHandler
- Menu, Tray, UnCheck, Start Second Group Applications with XBMC Launcher
- Menu, Tray, add, Second Group Apps Prevent Focus, MenuAppsPreventFocusHandler
- Menu, Tray, UnCheck, Second Group Apps Prevent Focus
- Menu, Tray, add ;add separator
- Menu, Tray, add, Open XBMC Programs Folder, MenuOpenXBMCFolderHandler
- Menu, Tray, add, Open XBMC Application Data Folder, MenuOpenXBMCAppFolderHandler
- Menu, Tray, add, Open XBMCLauncher Settings Folder, MenuOpenXBMCLauncherSettingsHandler
- Menu, Tray, add
- Menu, Tray, add, Turn off Display [Win+F11], MenuTurnOffDisplay
- Menu, Tray, add, About XBMCLauncher, MenuAboutHandler
- Menu, Tray, add
- Menu, tray, NoStandard
- Menu, tray, Standard
- if (FocusOnce = 1)
- Menu, Tray, Check, Check Focus Only Once
- if (ForceClose = 1)
- Menu, Tray, Check, Force Close XBMC on Suspend
- if (StartExplorer = 1)
- Menu, Tray, Check, Start Windows Explorer when XBMC is closed
- if (PressWinKey = 1)
- Menu, Tray, Check, Send Windows Key when XBMC is closed
- if (StartAtWinLogon = 1)
- Menu, Tray, Check, Start XBMC When Windows Starts
- if (StartAtWinResume = 1)
- Menu, Tray, Check, Start XBMC When Windows Resumes from Sleep
- if (StartApps = 1)
- Menu, Tray, Check, Start First Group Applications with XBMC Launcher
- if (StartApps_1 = 1)
- Menu, Tray, Check, Start Second Group Applications with XBMC Launcher
- if (PreventFocusApps = 1)
- Menu, Tray, Check, First Group Apps Prevent Focus
- if (PreventFocusApps_1 = 1)
- Menu, Tray, Check, Second Group Apps Prevent Focus
- ; >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> PROMPT FOR XBMC IF NOT FOUND <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
- IfNotExist, %XBMCPath% ; if xbmc.exe not exists, prompt to select xbmc.exe manually
- {
- MsgBox, 36, Select XBMC.exe, Could not locate XBMC executable file. Do you want to select the file manually?, 10
- ifMsgBox Yes
- {
- XBMCPath := SaveApplicationPath("XBMC", XBMCPath)
- if (ShowShutdownMenu <> 0)
- { SplitPath, XBMCPath, ,newpath
- FileCopy, %A_WorkingDir%\ShutdownAction.exe, %newpath%, 1
- FileCopy, %A_WorkingDir%\ShutdownAction.py, %newpath%, 1
- FileCopy, %A_WorkingDir%\CloseXBMC.exe, %newpath%, 1
- FileCopy, %A_WorkingDir%\CloseXBMC.py, %newpath%, 1
- FileCopy, %newpath%\addons\skin.confluence\720p\DialogButtonMenu.xml, %newpath%\addons\skin.confluence\720p\DialogButtonMenu_Backup.xml, 0
- FileCopy, %A_WorkingDir%\DialogButtonMenu.xml, %newpath%\addons\skin.confluence\720p, 1
- newdialogfile = %newpath%\addons\skin.confluence\720p\DialogButtonMenu.xml
- oldline2 = <onclick>XBMC.RunScript(ShutdownAction.py)</onclick>
- newline2 = <onclick>XBMC.RunScript(%newpath%\ShutdownAction.py)</onclick>
- TF_Replace("!" . newdialogfile, oldline2, newline2)
- oldline2 = <onclick>XBMC.RunScript(CloseXBMC.py)</onclick>
- newline2 = <onclick>XBMC.RunScript(%newpath%\CloseXBMC.py)</onclick>
- TF_Replace("!" . newdialogfile, oldline2, newline2)
- IniWrite, 0, %SettingsPath%, Settings, EditDialogButtonMenu
- IniWrite, 1, %SettingsPath%, Settings, UninstallDeleteFile
- }
- }
- }
- ; >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> LAUNCH APPLICATIONS <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
- If (StartAtWinLogon = 1)
- {
- Sleep %StartupDelay%
- LaunchApplication(XBMCPath)
- ;WinWait,XBMC,,6 ; wait 6 seconds
- WinActivate, ahk_class XBMC ; activate and bring to front.
- }
- LaunchApplication(iMONPath)
- LaunchApplication(XBMConiMONPath)
- If (StartApps = 1)
- {
- LaunchApplication(App1)
- LaunchApplication(App2)
- LaunchApplication(App3)
- }
- If (StartApps_1 = 1)
- {
- LaunchApplication(App4)
- LaunchApplication(App5)
- LaunchApplication(App6)
- }
- ; >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> MODIFY SHUTDOWN DIALOG BUTTON MENU - FOR CUSTOM MENU ONLY <<<<<<<<<<<<<<<<
- If (EditDialogButton = 1)
- {
- SplitPath, XBMCPath, , xbmcdir
- dialogfile = %xbmcdir%\addons\skin.confluence\720p\DialogButtonMenu.xml
- IfExist, %dialogfile%
- {
- oldline = <onclick>XBMC.RunScript(ShutdownAction.py)</onclick>
- newline = <onclick>XBMC.RunScript(%xbmcdir%\ShutdownAction.py)</onclick>
- TF_Replace("!" . dialogfile, oldline, newline)
- oldline = <onclick>XBMC.RunScript(CloseXBMC.py)</onclick>
- newline = <onclick>XBMC.RunScript(%xbmcdir%\CloseXBMC.py)</onclick>
- TF_Replace("!" . dialogfile, oldline, newline)
- IniWrite, 0, %SettingsPath%, Settings, EditDialogButtonMenu
- }
- }
- ModifyShutdownLabel(ShutdownLabel)
- {
- SplitPath, XBMCPath, , dir
- dialogfile1 = %dir%\addons\skin.confluence\720p\DialogButtonMenu.xml
- IfExist, %dialogfile1%
- { lbl := GetSettings("ShutdownLabel", "Shutdown")
- if (lbl <> ShutdownLabel)
- {
- oldline1 = <label>%lbl%</label>
- newline1 = <label>%ShutdownLabel%</label>
- TF_Replace("!" . dialogfile1, oldline1, newline1)
- }
- }
- }
- ; >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> START XBMC ON WINDOWS RESUME FROM HIBERNATION OR SLEEP <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
- OnMessage(0x218, "WM_POWERBROADCAST")
- WM_POWERBROADCAST(wParam, lParam)
- {
- If (wParam=4) ;suspend
- {
- Suspending = 1 ;System is suspending. Do not start Explorer.
- if (ForceClose = 1) ; force close xbmc
- {
- Process, Exist, xbmc.exe ; check to see if xbmc.exe is running
- If (ErrorLevel >= 1) ; If it is running
- {
- Process, Close, %ErrorLevel%
- Process, WaitClose, %ErrorLevel%
- sleep 1000
- }
- }
- }
- If (wParam=7 and StartAtWinResume = 1) ;on resuming from suspend state
- {
- LaunchApplication(XBMConiMONPath)
- Sleep %StartupDelay%
- ;WinWait,XBMC,,6 ; wait 6 seconds
- WinActivate, ahk_class XBMC ; activate and bring to front.
- LaunchApplication(XBMCPath)
- if (DisableFocusTemporarily = 1)
- {
- DisableFocusTemporarily() ;re enable focus
- }
- Suspending = 0
- FocussedOnce = 0
- }
- }
- ; >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> TIMER DECLARATIONS <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
- SetTimer, MonitorEvents, 500
- MonitorEvents:
- KeepFocus()
- StartExplorer()
- PressWinKey()
- MonitorCustomShutdown()
- DisableFocusOnExternalPlayer()
- return
- ; >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> SYSTEM TRAY MENU HANDLERS <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
- MenuStartXBMCHandler:
- {
- LaunchApplication(XBMCPath)
- Sleep, 2000
- WinActivate, ahk_class XBMC
- FocussedOnce = 0
- }
- return
- MenuStartXBMCAtWindowsLogonHandler:
- StartXBMCAtWinLogon()
- return
- MenuStartXBMCAtWindowsResumeHandler:
- StartXBMCAtWinResume()
- return
- MenuSetStartupDelayHandler:
- SetStartupDelay()
- return
- MenuSetFocusDelayHandler:
- SetFocusDelay()
- return
- MenuDisableFocusHandler:
- DisableFocusTemporarily()
- return
- MenuCheckFocusOnceHandler:
- CheckFocusOnce()
- return
- MenuSetXBMCPathHandler:
- XBMCPath := SaveApplicationPath("XBMC", XBMCPath)
- return
- MenuSetXBMConiMONPathHandler:
- XBMConiMONPath := SaveApplicationPath("XBMConiMON", XBMConiMONPath)
- return
- MenuSetiMONPathHandler:
- iMONPath := SaveApplicationPath("iMON", iMONPath)
- return
- MenuSetExternalPlayerHandler:
- ExternalPlayerPath := SaveApplicationPath("ExternalPlayer", ExternalPlayerPath)
- return
- MenuSetApp1Handler:
- SplitPath, App1, AppName
- if (AppName = "")
- AppName = Not Set
- oldmenuname = Set Application 1 - %AppName%
- App1 := SaveApplicationPath("App1", App1)
- SplitPath, App1, AppName
- if (AppName = "")
- AppName = Not Set
- newmenuname = Set Application 1 - %AppName%
- if (oldmenuname != newmenuname)
- {
- menu, tray, rename, %oldmenuname%, %newmenuname%
- }
- return
- MenuSetApp2Handler:
- SplitPath, App2, AppName
- if (AppName = "")
- AppName = Not Set
- oldmenuname = Set Application 2 - %AppName%
- App2 := SaveApplicationPath("App2", App2)
- SplitPath, App2, AppName
- if (AppName = "")
- AppName = Not Set
- newmenuname = Set Application 2 - %AppName%
- if (oldmenuname != newmenuname)
- {
- menu, tray, rename, %oldmenuname%, %newmenuname%
- }
- return
- MenuSetApp3Handler:
- SplitPath, App3, AppName
- if (AppName = "")
- AppName = Not Set
- oldmenuname = Set Application 3 - %AppName%
- App3 := SaveApplicationPath("App3", App3)
- SplitPath, App3, AppName
- if (AppName = "")
- AppName = Not Set
- newmenuname = Set Application 3 - %AppName%
- if (oldmenuname != newmenuname)
- {
- menu, tray, rename, %oldmenuname%, %newmenuname%
- }
- return
- MenuSetApp4Handler:
- SplitPath, App4, AppName
- if (AppName = "")
- AppName = Not Set
- oldmenuname = Set Application 4 - %AppName%
- App4 := SaveApplicationPath("App4", App4)
- SplitPath, App4, AppName
- if (AppName = "")
- AppName = Not Set
- newmenuname = Set Application 4 - %AppName%
- if (oldmenuname != newmenuname)
- {
- menu, tray, rename, %oldmenuname%, %newmenuname%
- }
- return
- MenuSetApp5Handler:
- SplitPath, App5, AppName
- if (AppName = "")
- AppName = Not Set
- oldmenuname = Set Application 5 - %AppName%
- App5 := SaveApplicationPath("App5", App5)
- SplitPath, App5, AppName
- if (AppName = "")
- AppName = Not Set
- newmenuname = Set Application 5 - %AppName%
- if (oldmenuname != newmenuname)
- {
- menu, tray, rename, %oldmenuname%, %newmenuname%
- }
- return
- MenuSetApp6Handler:
- SplitPath, App6, AppName
- if (AppName = "")
- AppName = Not Set
- oldmenuname = Set Application 6 - %AppName%
- App6 := SaveApplicationPath("App6", App6)
- SplitPath, App6, AppName
- if (AppName = "")
- AppName = Not Set
- newmenuname = Set Application 6 - %AppName%
- if (oldmenuname != newmenuname)
- {
- menu, tray, rename, %oldmenuname%, %newmenuname%
- }
- return
- MenuStartAppsHandler:
- SetStartApps()
- return
- MenuAppsPreventFocusHandler:
- SetPreventFocusApps()
- return
- MenuSetShutdownActionHandler:
- SetShutdownAction()
- return
- MenuForceCloseXBMCHandler:
- ForceCloseXBMC()
- return
- MenuStartExplorerHandler:
- SetStartExplorer()
- return
- MenuPressWinKeyHandler:
- SetPressWinKey()
- return
- MenuChangeShellHandler:
- ChangeShell()
- return
- MenuOpenXBMCAppFolderHandler:
- {
- appfolder := A_AppData . "\XBMC"
- ifexist, %appfolder%
- run %appfolder%
- }
- return
- MenuOpenXBMCFolderHandler:
- {
- SplitPath, XBMCPath, , xbmcfolder
- IfExist, %xbmcfolder%
- run %xbmcfolder%
- }
- return
- MenuOpenXBMCLauncherSettingsHandler:
- {
- SplitPath, SettingsPath, , settingsfolder
- IfExist, %settingsfolder%
- run %settingsfolder%
- }
- return
- MenuTurnOffDisplay:
- {
- Sleep 1000
- SendMessage 0x112, 0xF170, 2,,Program Manager
- }
- return
- MenuAboutHandler:
- {
- BreakFocus = 1
- MsgBox XBMCLauncher %version% `n`nAn application to customize your XBMC HTPC. `nDesigned and programmed by baijuxavior@gmail.com`n`nAdditional programming by Snood ;I hope you don't mind this addition
- }
- BreakFocus = 0
- return
- ; >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> FUNCTIONS <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
- KeepFocus()
- {
- if (FocusDelay = 0 or DisableFocusTemporarily = 1 or ExternalPlayerRunning = 1)
- {
- FocusCount = 0
- return
- }
- FocusCount := FocusCount + 1
- If (FocusCount = (FocusDelay * 2) // 1000)
- {
- FocusCount = 0
- if (FocusOnce = 0)
- {
- SendFocus()
- return
- }
- if (FocusOnce = 1 and FocussedOnce = 0)
- {
- SendFocus()
- FocussedOnce = 1
- }
- }
- }
- SendFocus()
- {
- Process, Exist, xbmc.exe ; check to see if xbmc.exe is running
- If (ErrorLevel >= 1 and BreakFocus = 0)
- WinActivate, ahk_class XBMC
- }
- GetSettings(SettingsName, DefaultValue) ;Get settings from Settings.ini file
- {
- If FileExist(SettingsPath)
- {
- IniRead, result, %SettingsPath%, Settings, %SettingsName%, %DefaultValue%
- return %result%
- }
- else
- return %DefaultValue%
- }
- SetFocusDelay() ;function to Change Focus Delay
- {
- BreakFocus = 1
- currentdelay := FocusDelay // 1000
- if currentdelay is not number
- currentdelay = 5
- InputBox, Delay, XBMCLauncher - Specify Time Delay, Specify the delay between refocussing of XBMC in seconds. `n `nEnter '0' seconds to prevent refocus permanently., , , , , , , , %currentdelay%
- If ErrorLevel ; If cancel was pressed
- {
- ;MsgBox cancel
- }
- else
- {
- If Delay is not number
- {
- Delay = 5000
- }
- Else
- {
- Delay := Delay * 1000
- }
- IniWrite, %Delay%, %SettingsPath%, Settings, Delay
- FocusDelay := Delay
- fdelaynew := FocusDelay // 1000
- old_name = Change Focus Delay [%currentdelay% sec]
- new_name = Change Focus Delay [%fdelaynew% sec]
- if (old_name != new_name)
- {
- menu, tray, rename, %old_name%, %new_name%
- }
- }
- BreakFocus = 0
- }
- LaunchApplication(AppPath) ; function to start applications
- {
- SplitPath, AppPath, FileName ;get filename without path
- Process, Exist, %FileName% ; check to see if 'FileName' is running
- If (ErrorLevel = 0) ;if not running
- {
- if FileExist(AppPath)
- {
- run %AppPath%
- }
- Else
- {
- ;traytip, Message, %AppPath% not found, 5, 1
- }
- }
- Else ; file already running
- {
- ;traytip, Message, %FileName% already running, 5, 1
- }
- }
- SaveApplicationPath(AppName, StartPath)
- {
- BreakFocus = 1
- FileSelectFile, SelectedFileName,1 ,%StartPath%, Select %AppName%.exe, *.exe
- if SelectedFileName !=
- {
- BreakFocus = 0
- IniWrite, %SelectedFileName%, %SettingsPath%, Settings, %AppName%_Path
- return %SelectedFileName%
- }
- else
- BreakFocus = 0
- return %StartPath%
- }
- StartXBMCAtWinLogon()
- {
- menu, tray, ToggleCheck, Start XBMC When Windows Starts
- if (StartAtWinLogon = 0)
- StartAtWinLogon = 1 ;enable. load xbmc
- else
- StartAtWinLogon = 0 ;disable. don't load
- IniWrite, %StartAtWinLogon%, %SettingsPath%, Settings, StartAtWinLogon
- return
- }
- StartXBMCAtWinResume()
- {
- menu, tray, ToggleCheck, Start XBMC When Windows Resumes from Sleep
- if (StartAtWinResume = 0)
- StartAtWinResume = 1 ;enable. load xbmc
- else
- StartAtWinResume = 0 ;disable. don't load
- IniWrite, %StartAtWinResume%, %SettingsPath%, Settings, StartAtWinResume
- return
- }
- DisableFocusTemporarily()
- {
- menu, tray, ToggleCheck, Disable Focus Temporarily [Win+F9]
- if (DisableFocusTemporarily = 0)
- DisableFocusTemporarily = 1 ;disable focus
- else
- DisableFocusTemporarily = 0 ;enable focus
- }
- DisableFocusOnExternalPlayer()
- {
- ExternalPlayerRunning = 0
- SplitPath, ExternalPlayerPath, playername
- Process, exist, %playername%
- If (ErrorLevel >= 1)
- ExternalPlayerRunning = 1
- if (PreventFocusApps = 1)
- {
- global appsname
- if (FileExist(App1))
- {SplitPath, App1, appsname
- ;if (appsname <> "")
- Process, exist, %appsname%
- If (ErrorLevel >= 1)
- ExternalPlayerRunning = 1
- }
- if (FileExist(App2))
- {SplitPath, App2, appsname
- ;if (appsname <> "")
- Process, exist, %appsname%
- If (ErrorLevel >= 1)
- ExternalPlayerRunning = 1
- }
- if (FileExist(App3))
- {SplitPath, App3, appsname
- ;if (appsname <> "")
- Process, exist, %appsname%
- If (ErrorLevel >= 1)
- ExternalPlayerRunning = 1
- }
- }
- if (PreventFocusApps_1 = 1)
- {
- global appsname
- if (FileExist(App4))
- {SplitPath, App4, appsname
- ;if (appsname <> "")
- Process, exist, %appsname%
- If (ErrorLevel >= 1)
- ExternalPlayerRunning = 1
- }
- if (FileExist(App5))
- {SplitPath, App5, appsname
- ;if (appsname <> "")
- Process, exist, %appsname%
- If (ErrorLevel >= 1)
- ExternalPlayerRunning = 1
- }
- if (FileExist(App6))
- {SplitPath, App6, appsname
- ;if (appsname <> "")
- Process, exist, %appsname%
- If (ErrorLevel >= 1)
- ExternalPlayerRunning = 1
- }
- }
- }
- CheckFocusOnce()
- {
- menu, tray, ToggleCheck, Check Focus Only Once
- if (FocusOnce = 0)
- FocusOnce = 1 ;enable. focus only once
- else
- FocusOnce = 0 ;disable. keep focussing
- IniWrite, %FocusOnce%, %SettingsPath%, Settings, FocusOnce
- return
- }
- ForceCloseXBMC()
- {
- menu, tray, ToggleCheck,Force Close XBMC on Suspend
- if (ForceClose = 0)
- ForceClose = 1 ;enable
- else
- ForceClose = 0 ;disable
- IniWrite, %ForceClose%, %SettingsPath%, Settings, ForceClose
- return
- }
- SetStartExplorer()
- {
- menu, tray, ToggleCheck,Start Windows Explorer when XBMC is closed
- if (StartExplorer = 0)
- {
- StartExplorer = 1 ;enable
- SetPressWinKey() ;turn off send win key option as using both is pointless, windows 8 explorer starts with the start menu anyway
- }
- else
- StartExplorer = 0 ;disable
- IniWrite, %StartExplorer%, %SettingsPath%, Settings, StartExplorer
- return
- }
- SetPressWinKey()
- {
- menu, tray, ToggleCheck,Send Windows Key when XBMC is closed
- if (PressWinKey = 0)
- {
- PressWinKey = 1 ;enable
- SetStartExplorer() ;turn off start explorer option as explorer must be running anyway
- Process, Exist, xbmc.exe ; check to see if xbmc.exe is running
- If (ErrorLevel = 0) ;if not running
- WinKeySent = 1 ;prevent win key from being sent immediately after setting is changed if XBMC is not running now
- }
- else
- PressWinKey = 0 ;disable
- IniWrite, %PressWinKey%, %SettingsPath%, Settings, PressWinKey
- return
- }
- SetStartApps()
- {
- menu, tray, ToggleCheck, Start First Group Applications with XBMC Launcher
- if (StartApps = 0)
- StartApps = 1 ;enable.
- else
- StartApps = 0 ;disable.
- IniWrite, %StartApps%, %SettingsPath%, Settings, StartApps
- menu, tray, ToggleCheck, Start Second Group Applications with XBMC Launcher
- if (StartApps_1 = 0)
- StartApps_1 = 1 ;enable.
- else
- StartApps_1 = 0 ;disable.
- IniWrite, %StartApps_1%, %SettingsPath%, Settings, StartApps_1
- return
- }
- SetPreventFocusApps()
- {
- menu, tray, ToggleCheck, First Group Apps Prevent Focus
- if (PreventFocusApps = 0)
- PreventFocusApps = 1 ;enable.
- else
- PreventFocusApps = 0 ;disable.
- IniWrite, %PreventFocusApps%, %SettingsPath%, Settings, PreventFocusApps
- menu, tray, ToggleCheck, Second Group Apps Prevent Focus
- if (PreventFocusApps_1 = 0)
- PreventFocusApps_1 = 1 ;enable.
- else
- PreventFocusApps_1 = 0 ;disable.
- IniWrite, %PreventFocusApps_1%, %SettingsPath%, Settings, PreventFocusApps_1
- return
- }
- SetShutdownAction() ;function to set shutdown
- {
- BreakFocus = 1
- ShutdownAction := GetSettings("Shutdown", "u")
- global S1
- global S2
- global S3
- Gui, Add, GroupBox, x1 y4 w350 h111 +Center, Select XBMC Shutdown Menu Action
- Gui, Add, Radio, % ( ShutdownAction = "u" ? "Checked" : "" ) " x10 y40 w70 h30 vS1" , Shutdown
- Gui, Add, Radio, % ( ShutdownAction = "s" ? "Checked" : "" ) " x140 y40 w70 h30 vS2" , Sleep
- Gui, Add, Radio, % ( ShutdownAction = "h" ? "Checked" : "" ) " x250 y40 w70 h30 vS3" , Hibernate
- Gui, Add, Button, x125 y78 w100 h30 , Apply
- Gui, Show, w352 h121, Select XBMC Shutdown Menu Action
- return
- ButtonApply:
- global newlabel
- Gui Submit, NoHide
- Gui Destroy
- If S1
- {
- Result = u
- newlabel = Shutdown
- }
- If S2
- {
- Result = s
- newlabel = Sleep
- }
- If S3
- {
- Result = h
- newlabel = Hibernate
- }
- IniWrite, %result%, %SettingsPath%, Settings, Shutdown
- MsgBox, 36, Modify XBMC Shutdown Menu Text, Do you want to change the Shutdown menu text also?
- ifMsgBox Yes
- {
- ModifyShutdownLabel(newLabel)
- IniWrite, %newLabel%, %SettingsPath%, Settings, ShutdownLabel
- }
- GuiClose:
- Gui, Destroy
- BreakFocus = 0
- Return
- }
- ChangeShell()
- {
- RegRead, ShellName, HKCU, Software\Microsoft\Windows NT\CurrentVersion\Winlogon, Shell
- SplitPath, ShellName, ShellName
- If ShellName != XBMCLauncher.exe
- {
- ShellName = Explorer.exe
- }
- BreakFocus = 1
- global SH1
- global SH2
- global shelln := RTrim(ShellName, "`.exe")
- global old_shellname := "Change Windows Shell [Current Shell - " . shelln . "]"
- Gui, Add, GroupBox, x1 y4 w250 h111 +Center, Change Windows Shell
- Gui, Add, Radio, % ( ShellName = "Explorer.exe" ? "Checked" : "" ) " x10 y40 w70 h30 vSH1" , Explorer
- Gui, Add, Radio, % ( ShellName = "XBMCLauncher.exe" ? "Checked" : "" ) " x140 y40 w100 h30 vSH2" , XBMCLauncher
- Gui, Add, Button, x75 y78 w100 h30 , Save
- Gui, Show, w252 h121, Change Windows Shell
- return
- ButtonSave:
- Result = "Explorer.exe"
- Gui Submit, NoHide
- Gui Destroy
- If SH1
- {Result = Explorer.exe
- shelln = Explorer
- }
- If SH2
- {Result = %A_WorkingDir%\XBMCLauncher.exe
- shelln = XBMCLauncher
- }
- RegWrite, REG_SZ, HKCU, Software\Microsoft\Windows NT\CurrentVersion\Winlogon, Shell, %Result%
- new_shellname = Change Windows Shell [Current Shell - %shelln%]
- if (old_shellname != new_shellname)
- {
- menu, tray, rename, %old_shellname%, %new_shellname%
- }
- Gui1Close:
- Gui, Destroy
- BreakFocus = 0
- Return
- }
- MonitorCustomShutdown()
- {
- ShutdownButtonClicked := GetSettings("ShutdownButtonClicked", 0)
- if (ShutdownButtonClicked = 1)
- {
- Process, Exist, xbmc.exe ; check to see if xbmc.exe is running
- If (ErrorLevel = 0) ; If it is closed
- {
- ShutdownAction := GetSettings("Shutdown", "u")
- IniWrite, 0, %SettingsPath%, Settings, ShutdownButtonClicked
- sleep 1000 ;wait one second
- if (ShutdownAction = "u") ;shutdown
- {
- objWMIService := ComObjGet("winmgmts:{impersonationLevel=impersonate}!\\" A_ComputerName "\root\cimv2")
- For objOperatingSystem in objWMIService.ExecQuery("Select * from Win32_OperatingSystem")
- ;Caption := objOperatingSystem.Caption , OSArchitecture := objOperatingSystem.OSArchitecture, CSDVersion := objOperatingSystem.CSDVersion, Version := objOperatingSystem.Version
- ;Msgbox % Caption "`n" OSArchitecture "`n" CSDVersion "`n" Version
- Version := objOperatingSystem.Version
- ;MsgBox %Version%
- if (Version >= 6.2) ; if windows 8
- ;MsgBox hybrid
- run, Shutdown.exe -s -hybrid -f -t 00, ,Hide
- else
- ;MsgBox full
- Shutdown, 5 ;shutdown = 1, force = 4
- }
- if (ShutdownAction = "r") ;reboot
- {
- Shutdown, 6 ;reboot = 2, force = 4
- }
- if (ShutdownAction = "s") ;sleep
- {
- DllCall("PowrProf\SetSuspendState", "int", 0)
- }
- if (ShutdownAction = "h") ;hibernate
- {
- DllCall("PowrProf\SetSuspendState", "int", 1)
- }
- }
- }
- }
- StartExplorer()
- {
- ShutdownButtonClicked := GetSettings("ShutdownButtonClicked", 0)
- if (StartExplorer = 1 and Suspending = 0 and ShutdownButtonClicked = 0) ;if not suspending
- {
- Process, Exist, xbmc.exe ; check to see if xbmc.exe is running
- If (ErrorLevel = 0) ;if not running
- Process, Exist, explorer.exe ; check to see if explorer.exe is running
- If (ErrorLevel = 0)
- Run, %A_WinDir%\Explorer.exe, %A_WinDir%
- }
- }
- PressWinKey()
- {
- ShutdownButtonClicked := GetSettings("ShutdownButtonClicked", 0)
- if (PressWinKey = 1 and Suspending = 0 and ShutdownButtonClicked = 0) ;if not suspending
- {
- Process, Exist, xbmc.exe ; check to see if xbmc.exe is running
- If (ErrorLevel = 0) ;if not running
- {
- Process, Exist, explorer.exe ; check to see if explorer.exe is running
- If (ErrorLevel >= 1) ;If running
- {
- If (WinKeySent = 0)
- SendInput {Lwin}
- WinKeySent = 1 ;prevents an infinite loop of win key presses
- }
- }
- else
- {
- WinKeySent = 0 ;reset WinKeySent if XBMC is opened again so that it will resend on next exit
- }
- }
- }
- SetStartupDelay()
- {
- BreakFocus = 1
- currentstartupdelay := StartupDelay // 1000
- if currentstartupdelay is not number
- currentstartupdelay = 0
- InputBox, StartDelay, XBMCLauncher - Specify Startup Delay, Specify the delay in seconds for XBMC to start., , , , , , , , %currentstartupdelay%
- If ErrorLevel ; If cancel was pressed
- {
- ;MsgBox cancel
- }
- else
- {
- If StartDelay is not number
- {
- StartDelay = 0
- }
- Else
- {
- StartDelay := StartDelay * 1000
- }
- IniWrite, %StartDelay%, %SettingsPath%, Settings, StartupDelay
- StartupDelay := StartDelay
- startdelaynew := StartupDelay // 1000
- startdelayold_name = Change Startup Delay [%currentstartupdelay% sec]
- startdelaynew_name = Change Startup Delay [%startdelaynew% sec]
- if (startdelayold_name != startdelaynew_name)
- {
- menu, tray, rename, %startdelayold_name%, %startdelaynew_name%
- }
- }
- BreakFocus = 0
- }
- return
- ; >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> HANDLE KEYBOARD SHORTCUTS FOR GREEN START BUTTON <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
- #F9::
- DisableFocusTemporarily()
- return
- $!F4::
- IfWinActive, ahk_class XBMC ; check to see if xbmc.exe is running
- {
- Send s
- return
- }
- IfWinNotActive, ahk_class XBMCLauncher
- Send !{F4}
- return
- #F10:: ;show traymenu
- DetectHiddenWindows, on
- WinExist( "AHK_Pid " DllCall("GetCurrentProcessId") ) ; make this script's main window the last found window
- WinActivate ; even though it's hidden, the target script's main window must be active for the menu to open
- SendMessage, 0x404, 0, 0x205 ; AHK_NOTIFYICON = 0x404, WM_RBUTTONUP = 0x205
- return
- #f11:: ; Turn off Display Screen
- ;Run,%A_WinDir%\System32\rundll32.exe user32.dll`,LockWorkStation
- Sleep 1000
- SendMessage 0x112, 0xF170, 2,,Program Manager
- return
- #!Enter:: ; Win+Alt+Enter shortcut key
- LaunchApplication(XBMCPath)
- ;Sleep, 2000
- WinActivate, ahk_class XBMC
- FocussedOnce = 0
- LaunchApplication(iMONPath)
- LaunchApplication(XBMConiMONPath)
- Sleep, 5000
- WinActivate, ahk_class XBMC
- WinGet, Style, Style, ahk_class XBMC
- if (Style & 0xC00000) ;Detects if XBMC has a title bar.
- {
- Send {VKDC} ;Maximize XBMC to fullscreen mode if its in a window mode.
- }
- Return
- SetTitleMatchMode 2
- #IfWinActive XBMC ahk_class XBMC ; XBMC detection for XBMC/GSB Home Screen action.
- #!Enter::
- WinGet, Style, Style, ahk_class XBMC
- if (Style & 0xC00000) ;Detects if XBMC has a title bar.
- {
- Send {VKDC} ;Maximize XBMC to fullscreen mode if its in a window mode.
- }
- WinMaximize ;Maximize XBMC if Windowed.
- send, ^!{VK74} ; if XBMC is Active (GSB Home Jump will activate)
- Return
- #IfWinActive ;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement