Skip to content

Instantly share code, notes, and snippets.

@bellbind
Created Dec 13, 2009
Embed
What would you like to do?
[c#]snippet for access system key map
// access key maps
using Microsoft.Win32;
class KeyMap {
static void Main(string[] args) {
// Windows7 does not support Keyboard Layout in CurrentUser
//var root = Registry.CurrentUser;
//var subkey = @"Keyboard Layout"; // for CurrentUser
var root = Registry.LocalMachine;
var subkey = @"SYSTEM\CurrentControlSet\Control\Keyboard Layout";
using (var regkey = root.OpenSubKey(subkey)) {
// Scancode Map is REG_BINARY
var maps = regkey.GetValue("Scancode Map") as byte[];
// scancode map spec
// dword1 : 0x0000-0000 : 1st dword always 0
// dword2 : 0x0000-0000 : 2nd dword always 0
// dword3 : 0x0000-0002 : 3rd dword is mapping count + 1 (data size)
// dword4 : 0x003a-e01d : Caps Lock(003a) -> RCtrl(e01d)
// dword5 : 0x0000-0000 : last dword always 0
for (var i = 0; i < maps.Length; i += 4) {
uint dw = System.BitConverter.ToUInt32(maps, i);
System.Console.WriteLine("dword: 0x{0:x4}-{1:x4}", dw >> 16, dw & 0xffff);
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment