Last active
April 20, 2024 11:44
-
-
Save don-smith/415540556e5d281aa449b6305e03751a to your computer and use it in GitHub Desktop.
A PowerShell script to swap the Caps Lock and Ctrl keys
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Script found at https://superuser.com/a/997448 | |
# Swap details found at https://www.mavjs.org/post/swap-ctrl-and-capslock-on-windows | |
# Improvement provided by Davido264 in comment below | |
$hexified = "00,00,00,00,00,00,00,00,03,00,00,00,1d,00,3a,00,3a,00,1d,00".Split(',') | % { "0x$_"}; | |
$kbLayout = 'HKLM:\System\CurrentControlSet\Control\Keyboard Layout'; | |
$scancodeMap = Get-ItemProperty -Path $kbLayout -Name "Scancode Map" -ErrorAction Ignore | |
if ( -not $scancodeMap ) | |
{ | |
New-ItemProperty -Path $kbLayout -Name "Scancode Map" -PropertyType Binary -Value ([byte[]]$hexified); | |
} | |
else | |
{ | |
Set-ItemProperty -LiteralPath $kbLayout -Name "Scancode Map" -Value ([byte[]]$hexified); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
It worked, thanks.
One thing I want to say, is you can use
Get-ItemProperty
to check ifScancode Map
exists, so it's not necesary to modify the script when running the first time