-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathrefresh_remap.ps1
More file actions
26 lines (24 loc) · 1.59 KB
/
refresh_remap.ps1
File metadata and controls
26 lines (24 loc) · 1.59 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
# Auto-detect system by board name
$systemName = if ($ENV:SYSTEM_NAME) { $ENV:SYSTEM_NAME } else { (Get-WmiObject -class Win32_BaseBoard).Product }
# Kill ahk_REMAP.exe and the keyboard remap .ahk script
$killed = 0
taskkill /IM "ahk_REMAP.exe" /F 2>$null; if ($LASTEXITCODE -eq 0) { Write-Host "Killed ahk_REMAP.exe"; $killed++ }
taskkill /IM "ahk_keyboard_remap_$systemName.exe" /F 2>$null; if ($LASTEXITCODE -eq 0) { Write-Host "Killed ahk_keyboard_remap_$systemName.exe"; $killed++ }
taskkill /IM "ahk_keyboard_remap_all.exe" /F 2>$null; if ($LASTEXITCODE -eq 0) { Write-Host "Killed ahk_keyboard_remap_all.exe"; $killed++ }
Get-CimInstance Win32_Process | Where-Object { $_.CommandLine -like "*ahk_keyboard_remap*" -or $_.CommandLine -like "*ahk_REMAP*" } | ForEach-Object {
Write-Host "Killed PID $($_.ProcessId): $($_.Name)"
Stop-Process -Id $_.ProcessId -Force -ErrorAction SilentlyContinue
$killed++
}
if ($killed -eq 0) { Write-Host "No remap processes were running" }
Start-Sleep -Milliseconds 200
# Start keyboard remap: system-specific if exists, else fallback to all
$kbRemapDir = Join-Path $PSScriptRoot "KeyboardRemap"
$kbRemapScript = Join-Path $kbRemapDir "ahk_keyboard_remap_$systemName.exe.ahk"
if (-not (Test-Path $kbRemapScript)) {
$kbRemapScript = Join-Path $kbRemapDir "ahk_keyboard_remap_all.exe.ahk"
}
$ahkExe = "C:\Program Files\AutoHotkey\AutoHotkey.exe"
if (-not (Test-Path $ahkExe)) { $ahkExe = "C:\Program Files\AutoHotkey\AutoHotkeyU64.exe" }
Start-Process -FilePath $ahkExe -ArgumentList "`"$kbRemapScript`"" -WorkingDirectory $kbRemapDir
Write-Host "Started $kbRemapScript"