Skip to content

Instantly share code, notes, and snippets.

@don-smith
Last active April 20, 2024 11:44
Show Gist options
  • Save don-smith/415540556e5d281aa449b6305e03751a to your computer and use it in GitHub Desktop.
Save don-smith/415540556e5d281aa449b6305e03751a to your computer and use it in GitHub Desktop.
A PowerShell script to swap the Caps Lock and Ctrl keys
# 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);
}
@don-smith
Copy link
Author

Nice one! Thanks @Davido264

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment