Last active
October 5, 2020 16:21
-
-
Save bjarkirafn/bf958982ae96732773c5ba418d8fc896 to your computer and use it in GitHub Desktop.
posh:keymap
This file contains 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
$null = Add-Type -AssemblyName System.Windows.Forms -PassThru | |
function ConvertFrom-Enum { | |
param([String]$TypeName) | |
$Type = [Type]$TypeName | |
$obj = [pscustomobject]@{} | |
$Type.GetEnumNames() | | |
ForEach-Object { | |
$obj | Add-Member $_ ([int]$Type::$_) -Force | |
} | |
return $obj | |
} | |
$VKeys = ConvertFrom-Enum System.Windows.Forms.Keys | |
$VKeys | |
$ConsoleKeys = ConvertFrom-Enum System.ConsoleKey | |
$ConsoleKeys | |
$EscapeScancode = 'E01C99' | |
[int]"0x$EscapeScancode" | |
$bytes = [byte[]] -split ($EscapeScancode -replace '..', "0x$& ") | |
$bytes | Measure-Object -Sum | |
class KeyCode { | |
[string]$Name | |
[string]$Console | |
[string]$Hex | |
[int]$Number | |
KeyCode([int]$num) { | |
$this.Name = [Windows.Forms.Keys]$num | |
try { | |
$this.Console = [ConsoleKey]$num | |
} | |
catch { | |
$this.Console = '' | |
# $key = [ConsoleKey].GetEnumNames() | | |
# Where-Object { [ConsoleKey]::$_.value__ -eq $num } | |
# $this.Console = $key ? $key[0] : 'NONE' | |
} | |
$this.Hex = $num.ToString('X2') | |
$this.Number = $num | |
} | |
} | |
1..143 | ForEach-Object { [KeyCode]::new($_) } | |
$value = [byte[]] ( | |
0x00, 0x00, 0x00, 0x00, | |
0x00, 0x00, 0x00, 0x00, | |
0x02, 0x00, 0x00, 0x00, # Number of mappings + 1 Terminator | |
0x1C, 0x00, 0x3A, 0x00, # Caps Lock to Enter | |
0x00, 0x00, 0x00, 0x00 # final four bytes | |
) | |
function Convert-IntToScancode { | |
param([int]$Number, [int]$Bits = 4, [bool]$Reverse = $true) | |
$Hex = -split ($Number.ToString("X$Bits") -replace '..', '$& ') | |
if ($Number -eq 0 -or -not $Reverse) { | |
return $Hex -join ' ' | |
} | |
[array]::Reverse($Hex) | |
return $Hex -join ' ' | |
} | |
$nums = [int[]]@( | |
0, 0, | |
0, 0, | |
2, 0, | |
57436, 28, | |
0, 0 | |
) | |
$string = New-Object System.Text.StringBuilder | |
for ($i = 0; $i -lt $nums.Count; $i += 2) { | |
$n1, $n2 = $i..($i + 1) | | |
ForEach-Object { | |
$reverse = $_ -ne 4 | |
Convert-IntToScancode $nums[$_] -Reverse $reverse } | |
$null = $string.Append("$n1 $n2`n") | |
} | |
$string.ToString() | |
function ConvertTo-RegistryScancode { | |
param([int[]]$Keys) | |
$ParsedKeys = $Keys | ForEach-Object { | |
if ($_.Length -eq 2) { | |
$_ = "00$_" | |
} | |
($_ -replace '..', '$& ').TrimEnd() | |
} | |
} | |
$ScancodeMap = @{ | |
Path = 'HKLM:\SYSTEM\CurrentControlSet\Control\Keyboard Layout' | |
Name = 'Scancode Map' | |
Value = $value | |
} | |
$scanCodesRaw = @' | |
0001 ESC | |
0002 1 | |
0003 2 | |
0004 3 | |
0005 4 | |
0006 5 | |
0007 6 | |
0008 7 | |
0009 8 | |
000A 9 | |
000B 0 | |
000C Subtract _ | |
000D Equal Oemplus | |
000E BackSpace | |
000F Tab | |
0010 Q | |
0011 W | |
0012 E | |
0013 R | |
0014 T | |
0015 Y | |
0016 U | |
0017 I | |
0018 O | |
0019 P | |
001A [ { | |
001B ] } | |
001C Enter | |
E01C Enter | |
001D LCtrl | |
E01D RCtrl | |
001E A | |
001F S | |
0020 D | |
0021 F | |
0022 G | |
0023 H | |
0024 J | |
0025 K | |
0026 L | |
0027 OemSemicolon Oemcolon | |
0028 OemQuotes " | |
0029 ` Oemtilde | |
002A LShiftKey | |
002B OemBackslash OemPipe | |
002C Z | |
002D X | |
002E C | |
002F V | |
0030 B | |
0031 N | |
0032 M | |
0033 Oemcomma < | |
0034 OemPeriod > | |
0035 / OemQuestion | |
0036 RShiftKey | |
0037 PrintScreen | |
E037 Ctrl+PrintScreen | |
0038 LAlt | |
E038 RAlt | |
0039 Space | |
003A CapsLock | |
003B F1 | |
003C F2 | |
003D F3 | |
003E F4 | |
003F F5 | |
0040 F6 | |
0041 F7 | |
0042 F8 | |
0043 F9 | |
0044 F10 | |
0045 NumLock | |
0046 ScrollLock | |
0047 Home | |
0048 UpArrow | |
0049 PageUp | |
004A Subtract | |
004B 4 Left | |
004C 5 | |
004D 6 Right | |
004E Add | |
004F 1 End | |
0050 2 Down | |
0051 3 PageDown | |
0052 0 Insert | |
0053 Delete . | |
0054 Shift+F1 | |
0055 Shift+F2 | |
0056 Shift+F3 | |
0057 Shift+F4 | |
0058 Shift+F5 | |
0059 Shift+F6 | |
005A Shift+F7 | |
005B Shift+F8 | |
E05B LWin | |
005C Shift+F9 | |
E05C RWin | |
005D Shift+F10 | |
E05D RMenu | |
005E Ctrl+F1 | |
005F Ctrl+F2 | |
0060 Ctrl+F3 | |
0061 Ctrl+F4 | |
0062 Ctrl+F5 | |
0063 Ctrl+F6 | |
0064 Ctrl+F7 | |
0065 Ctrl+F8 | |
0066 Ctrl+F9 | |
0067 Ctrl+F10 | |
0068 Alt+F1 | |
0069 Alt+F2 | |
006A Alt+F3 | |
006B Alt+F4 | |
006C Alt+F5 | |
006D Alt+F6 | |
006E Alt+F7 | |
006F Alt+F8 | |
0070 Alt+F9 | |
0071 Alt+F10 | |
0072 Ctrl+PrintScreen | |
0073 Ctrl+Left | |
0074 Ctrl+Right | |
0075 Ctrl+End | |
0076 Ctrl+PageDown | |
0077 Ctrl+Home | |
0078 Alt+1 | |
0079 Alt+2 | |
007A Alt+3 | |
007B Alt+4 | |
007C Alt+5 | |
007D Alt+6 | |
007E Alt+7 | |
007F Alt+8 | |
0080 Alt+9 | |
0081 Alt+0 | |
0082 Alt+- | |
0082 Alt+= | |
0084 Ctrl+PageUp | |
0085 F11 | |
0086 F12 | |
0087 Shift+F11 | |
0088 Shift+F12 | |
0089 Ctrl+F11 | |
008A Ctrl+F12 | |
008B Alt+F11 | |
008C Alt+F12 | |
008C Ctrl+Up | |
008E Ctrl+- (num) | |
008F Ctrl+5 (num) | |
0090 Ctrl++ (num) | |
0091 Ctrl+Down | |
0092 Ctrl+Ins | |
0093 Ctrl+Del | |
0094 Ctrl+Tab | |
0095 Ctrl+/ (num) | |
0096 Ctrl+* (num) | |
0097 Alt+Home | |
0098 Alt+Up | |
0099 Alt+PageUp | |
009A | |
009B Alt+Left | |
009C | |
009D Alt+Right | |
009E | |
009F Alt+End | |
00A0 Alt+Down | |
00A1 Alt+PageDown | |
00A2 Alt+Ins | |
00A3 Alt+Delete | |
00A4 Alt+/ (num) | |
00A5 Alt+Tab | |
00A6 Alt+Enter (num) | |
'@ | |
$ScanCodes = [pscustomobjec]@{} | |
$scanCodesRaw | Select-String '(?m)(?<Hex>^.. ..) (?<Key>.*$)' -AllMatches | | |
ForEach-Object { | |
$groups = $_.matches.Groups | |
$Hex = ($groups | Where-Object { $_.Name -like 'Hex' }).Value | |
$Key = ($groups | Where-Object { $_.Name -like 'Key' }).Value | |
$Int = [int]"0x$Hex" | |
$Key | |
} | |
function New-DynamicEnum { | |
[OutputType([String])] | |
param([string]$Name, [pscustomobject]$Enum) | |
$Signature = @" | |
public enum $Name | |
{ | |
$(($Enum.psobject.properties | | |
ForEach-Object { "`t{0} = {1}" -f $_.Name, $_.Value }) -join ",`n") | |
} | |
"@ | |
Add-Type -MemberDefinition $Signature -Name $Name -Namespace JaHer | |
return | |
} | |
$ConsoleKeysSignature = New-DynamicEnum 'ConsoleKeys' $ConsoleKeys | |
$VKeysSignature = New-DynamicEnum 'VKeys' $VKeys | |
$keyboard101 = @' | |
--- --------------- --------------- --------------- ----------- | |
| 01| | 3B| 3C| 3D| 3E| | 3F| 40| 41| 42| | 43| 44| 57| 58| |+37|+46|+45| | |
--- --------------- --------------- --------------- ----------- | |
----------------------------------------------------------- ----------- --------------- | |
| 29| 02| 03| 04| 05| 06| 07| 08| 09| 0A| 0B| 0C| 0D| 0E| |*52|*47|*49| |+45|+35|+37| 4A| | |
|-----------------------------------------------------------| |-----------| |---------------| | |
| 0F| 10| 11| 12| 13| 14| 15| 16| 17| 18| 19| 1A| 1B| 2B| |*53|*4F|*51| | 47| 48| 49| | | |
|-----------------------------------------------------------| ----------- |-----------| 4E| | |
| 3A| 1E| 1F| 20| 21| 22| 23| 24| 25| 26| 27| 28| 1C| | 4B| 4C| 4D| | | |
|-----------------------------------------------------------| --- |---------------| | |
| 2A| 2C| 2D| 2E| 2F| 30| 31| 32| 33| 34| 35| 36| |*4C| | 4F| 50| 51| | | |
|-----------------------------------------------------------| ----------- |-----------|-1C| | |
| 1D|-5B| 38| 39|-38|-5C|-5D| -1D| |*4B|*50|*4D| | 52| 53| | | |
----------------------------------------------------------- ----------- --------------- | |
'@ |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment