The following, arguably useless mapping, demonstratres how an environment can be created where 6
is mapped to 5
, A
is mapped to 6
and 5
to A
.
Swapping ESC and Caps Lock
The following script is (at least for my purposes) more useful:
$s_ESC = 0x01, 0x00
$s_CAPS = 0x3a, 0x00
$s_RWIN = 0x5c, 0xe0
$s_RCTR = 0x1d, 0xe0
$mapping = [byte[]] (
0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00,
0x04, 0x00, 0x00, 0x00+ # 3 mapping + 1 ending = 0x04
$s_ESC + $s_CAPS + # 1st mapping: caps lock -> escape
$s_CAPS + $s_ESC + # 2nd mapping: escape -> caps lock
$s_RCTR + $s_RWIN + # 3rd mapping: right windows -> right control
0x00, 0x00, 0x00, 0x00 # final four bytes
)
$null = new-itemProperty -path "HKLM:\SYSTEM\CurrentControlSet\Control\Keyboard Layout" -name "Scancode Map" -value $mapping -force
After changing the scan map, the computer needs to be restarted.
Update
2022-07-23: I used this script in a
Oracle VirtualBox guest. It turns out it modifies the keys only
if the guest OS is runnning in
full screen mode.
The following ascii-art tries to show the Scancode map more graphically:
"Scancode Map"=hex:00,00,00,00,00,00,00,00,04,00,00,00,01,00,3a,00,3a,00,01,00,1d,e0,5c,e0,00,00,00,00
; | DWORD 1 | DWORD 2 | 3 Maps | Map 1 | Map 2 | Map 3: | Final
; +-----------+-----------+-----------+-----------+-------------
; | | | | | Final 4 bytes
; | + 1 0000 | | | Map 3: Right Windows to Right Ctrl
; | Ending | | Map 2: Escape to Caps Lock
; | | Map 1: Caps Lock to Escape