diff --git a/README.md b/README.md index 114f90d..c5580af 100644 --- a/README.md +++ b/README.md @@ -1,9 +1,9 @@ # simlauncher + A PowerShell script to launch different applications when a game controller is detected -Run the script in Powershell and follow the instruction to detect your game controller. +Run the find.ps1 script in Powershell and follow the instructions to detect your game controller. -Once you set the $DeviceID variable you can create a task triggered on computer unlock to execute the .bat file: -wheel.bat +Once you set the $DeviceID variable in the wheel.ps1 script you can create a task triggered on computer unlock to execute the .bat file: -The .ps1 file has a infinite while loop and will monitor USB every second. +wheel.bat diff --git a/find.ps1 b/find.ps1 new file mode 100644 index 0000000..a943de9 --- /dev/null +++ b/find.ps1 @@ -0,0 +1,24 @@ + +clear + +$Devices = gwmi -Query "SELECT DeviceID FROM Win32_PNPEntity WHERE Description LIKE '%game%'" +$InitialDeviceIds = @() +$NewDeviceCount = 0 + +foreach ($Device in $Devices) { + $InitialDeviceIds += $Device.DeviceID +} + +echo 'Initialised device list, turn on wheelbase' +Read-Host 'Press Enter to continue' | Out-Null + +$Devices=gwmi -Query "SELECT DeviceID FROM Win32_PNPEntity WHERE Description LIKE '%game%'" + +foreach ($Device in $Devices) { + if ($InitialDeviceIds -notcontains $Device.DeviceID) { + echo 'New device: {0}' -F $Device.DeviceID + $NewDeviceCount++ + } +} + +echo "Found $NewDeviceCount new device(s)" \ No newline at end of file diff --git a/wheel.ps1 b/wheel.ps1 index 666d609..17ca979 100644 --- a/wheel.ps1 +++ b/wheel.ps1 @@ -1,79 +1,40 @@ - -#Start the script and follow the instuctions. -#Copy the DeviceID, for example: HID\VID_0EB7&PID_6204\7&210F0DBA&0&0000 -#Then set the DeviceID variable like this example: -#$DeviceID="7&210F0DBA&0&0000" - -$DeviceID="" - -#Do not modify below this point unless you know what are you doing! - -if(!$DeviceID){ -clear -echo "Turn off or disconnect your Wheelbase" -Read-Host 'Press Enter to continue…' | Out-Null -echo "Reading current game controllers..." -$devices=gwmi -Query "SELECT DeviceID FROM Win32_PNPEntity WHERE Description LIKE '%game%'" -clear -echo "Now turn on/connect your wheel" -Read-Host 'Press Enter to continue…' | Out-Null -while($devices){ -clear -echo "Detecting new USB device..." -start-sleep -s 5 -$newdevice=gwmi -Query "SELECT DeviceID FROM Win32_PNPEntity WHERE Description LIKE '%game%'" -if($newdevice -ne $devices){ - echo "Found new device!" - Read-Host 'Press Enter to continue…' | Out-Null - $newdvice=$newdevice[@($devices).length] - break -} -} -clear -echo "Your wheel device id is:" -echo $newdevice[0].DeviceID -echo "" -echo "Copy the DeviceID, for example: HID\VID_0EB7&PID_6204\7&210F0DBA&0&0000" -echo "Then set the DeviceID variable on line 7 like this example:" -echo "`$DeviceID=`"7&210F0DBA&0&0000`"" -Read-Host 'Press Enter to quit.' | Out-Null -} - -$wheel="" -$wheelwas=0 - -while($true -And $DeviceID) -{ - -$wheel=gwmi -Query "SELECT * FROM Win32_PNPEntity WHERE DeviceID LIKE '%$DeviceID%'" -clear -echo "Monitoring device id $DeviceID" -if(!$wheelwas -And $wheel){ - $wheelwas=1 - Add-Type -AssemblyName System.Windows.Forms - $global:balloon = New-Object System.Windows.Forms.NotifyIcon - $path = (Get-Process -id $pid).Path - $balloon.Icon = [System.Drawing.Icon]::ExtractAssociatedIcon($path) - $balloon.BalloonTipIcon = [System.Windows.Forms.ToolTipIcon]::Warning - $balloon.BalloonTipText = 'Wheel is on, starting up apps...' - $balloon.BalloonTipTitle = "Attention $Env:USERNAME" - $balloon.Visible = $true - $balloon.ShowBalloonTip(5000) - wmic process where "name='CrewChiefV4.exe'" delete - start "C:\ProgramData\Microsoft\Windows\Start Menu\Programs\CrewChief" - start "C:\Program Files (x86)\Rhinode LLC\Trading Paints\Trading Paints.exe" - start "C:\Program Files (x86)\iRacing Setup Sync\iRacingSetupSyncLauncher.exe" - start "C:\Program Files (x86)\iSpeed\iSpeed.exe" - start "C:\Program Files\SimRacingStudio\simracingstudio.exe" - -} ElseIf(!$wheel) { - $wheelwas=0 - echo "wheel is OFF" -} - -if($wheelwas){ -echo "wheel is ON" -} - -start-sleep -s 1 -} +#Paste the device ID from the find.ps1 script here: +$DeviceID = "" + +$ShowNotification = $false + +#Do not modify below this point unless you know what are you doing! + +clear + +echo 'Waiting for wheelbase...' + +while ($true) { + $Wheel = gwmi -Query "SELECT * FROM Win32_PNPEntity WHERE DeviceID = '$DeviceID'" + + if ($Wheel) { + echo 'Found!' + if ($ShowNotification) { + Add-Type -AssemblyName System.Windows.Forms + $Global:Balloon = New-Object System.Windows.Forms.NotifyIcon + $Path = (Get-Process -id $pid).Path + $Balloon.Icon = [System.Drawing.Icon]::ExtractAssociatedIcon($Path) + $Balloon.BalloonTipIcon = [System.Windows.Forms.ToolTipIcon]::Warning + $Balloon.BalloonTipText = 'Wheel is on, starting up apps...' + $Balloon.BalloonTipTitle = "Attention $Env:USERNAME" + $Balloon.Visible = $true + $Balloon.ShowBalloonTip(5000) + } + + wmic process where "name='CrewChiefV4.exe'" delete + start "C:\ProgramData\Microsoft\Windows\Start Menu\Programs\CrewChief" + start "C:\Program Files (x86)\SimHub\SimHubWPF.exe" + start "C:\Program Files (x86)\Rhinode LLC\Trading Paints\Trading Paints.exe" + start "C:\Program Files (x86)\iRacing Setup Sync\iRacingSetupSyncLauncher.exe" + start "C:\Program Files (x86)\iSpeed\iSpeed.exe" + start "C:\Program Files\SimRacingStudio\simracingstudio.exe" + break + } + + start-sleep -s 10 +} \ No newline at end of file