Posts tagged keyremap

Remapping Keys in Windows 7 through registry
posted on 2013-11-24 19:18:44

For easier keyboard handling (and to save my fingers) I tend to switch Capslock and right CTRL, as well as left CTRL and left ALT/ALT Gr. For Windows there exist external programs like AutoHotkey and others, but I prefer doing it more low-level through the Windows Registry.

To do this, a key has to be set at HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\Keyboard Layout. To check if it exists (or look up its current setting), WIN+R regedit, and navigate there. (This is just regedit in Windows Run Dialogue.) Note that the key is named Keyboard Layout, not Keyboard Layouts, do not change the latter.

If there is nothing present, do not worry. First a look on the theory and how the key is structured. Easiest to use are .reg files, a working example may look like this:

Windows Registry Editor Version 5.00

[HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\Keyboard Layout]
"Scancode Map"=hex:00,00,00,00,00,00,00,00,05,00,00,00,1d,00,3a,00,3a,00,1d,00,38,e0,1d,e0,1d,e0,38,e0,00,00,00,00 

This switches right CTRL with right ALT and left CTRL with CapsLock.

Looks complicated? This text here can actually be pasted into an empty .txt file. Rename it then to my_keymap.reg (Change the extension so Windows realizes to process this as a registry file.) and double click. Approve the changes, reboot, and you have a sticking change of your keymap. (To undo, delete the registry key and reboot.)

For easier explaining, the same code again, but with some formatting applied, and line numbers added:

 1      Windows Registry Editor Version 5.00
 2  
 3      [HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\Keyboard Layout]
 4      "Scancode Map"=hex:
 5  
 6      00,00,00,00,
 7      00,00,00,00,
 8      
 9      05,00,00,00,
10  
11      1d,00,3a,00,
12      3a,00,1d,00,
13      38,e0,1d,e0,
14      1d,e0,38,e0,
15  
16      00,00,00,00 

This looks a bit better. But what do these hex-combos mean?

DWORDS (Windows data type representing a 32bit unsigned int) in lines 6, 7 and 16 are ALWAYS zeroes. The last one is a null terminator, the first ones are version information and flags as a header. Header information is always zeroes in the current version of the Scan Code Mapper.

Line 9 is a counter of all the DWORDs representing remappings that follow (Lines 11 to 14 are four mappings) plus the terminator in line 16. That is why there is a 5. This depends on how many mappings you create and has to be set accordingly. For comparison in an example without a single remapping, it should be set to 1 and will then look like this:

 1      Windows Registry Editor Version 5.00
 2  
 3      [HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\Keyboard Layout]
 4      "Scancode Map"=hex:
 5  
 6      00,00,00,00,
 7      00,00,00,00,
 8      
 9      01,00,00,00,
10  
11      00,00,00,00 

But no need to create a reg-key like this if you want to have the changes removed again, just delete the HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\Keyboard Layout key and reboot.

These lines from the former example:

11      1d,00,3a,00,
12      3a,00,1d,00,
13      38,e0,1d,e0,
14      1d,e0,38,e0,

are where actually keys are remapped. The first two bytes represent the key's keycode that will be used, the last two bytes represent the key that is changed.

So,

11      1d,00,3a,00,

just means map L-Ctrl (1d) onto Caps-Lock (3a). Line 12 is the same keys, but in reverse, 13 and 14 switches R-Alt and R-Ctrl. (Comes in handy for emacs usage.)

Keycodes were taken from this document here, which I stumbled upon somewhere in the msdn pages. See column 'scan 1 make', the first one of each eight entries, page 16 onwards. Note that i.e. Right Alt is noted as e0_38, but when used as the first half of the DWORD in line 13 or the second half in line 14, it's bytes are actually switched.

A last example, this one just replaces Capslock with R-Ctrl:

Windows Registry Editor Version 5.00

[HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\Keyboard Layout]
"Scancode Map"=hex:

00,00,00,00,
00,00,00,00,

02,00,00,00,

1d,00,3a,00,

00,00,00,00 

Last three DWORDS are 02,00,00,00,, since two more lines are following, the actual rebind and finally the null terminator.

If you copy paste this, it will not work. You have to reformat, so that there are no newlines in there:

Windows Registry Editor Version 5.00

[HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\Keyboard Layout]
"Scancode Map"=hex:00,00,00,00,00,00,00,00,01,00,00,00,1d,00,3a,00,00,00,00,00 

This code can be pasted to a file named choose-a-name.reg. Save, double-click, reboot, and your CapsLock key will be gone. If you are interested in the original Microsoft article have based this on, which is from 2001, go here. Also this link helped.

This blog covers .csv, .htaccess, .pfx, .vmx, /etc/crypttab, /etc/network/interfaces, /etc/sudoers, /proc, 10.04, 14.04, AS, ASA, ControlPanel, DS1054Z, GPT, HWR, Hyper-V, IPSEC, KVM, LSI, LVM, LXC, MBR, MTU, MegaCli, PHP, PKI, R, RAID, S.M.A.R.T., SNMP, SSD, SSL, TLS, TRIM, VEEAM, VMware, VServer, VirtualBox, Virtuozzo, XenServer, acpi, adaptec, algorithm, ansible, apache, apachebench, apple, arcconf, arch, architecture, areca, arping, asa, asdm, awk, backup, bandit, bar, bash, benchmarking, binding, bitrate, blackarmor, blowfish, bochs, bond, bonding, booknotes, bootable, bsd, btrfs, buffer, c-states, cache, caching, ccl, centos, certificate, certtool, cgdisk, cheatsheet, chrome, chroot, cisco, clamav, cli, clp, clush, cluster, coleslaw, colorscheme, common lisp, console, container, containers, controller, cron, cryptsetup, csync2, cu, cups, cygwin, d-states, database, date, db2, dcfldd, dcim, dd, debian, debug, debugger, debugging, decimal, desktop, df, dhclient, dhcp, diff, dig, display manager, dm-crypt, dmesg, dmidecode, dns, docker, dos, drivers, dtrace, dtrace4linux, du, dynamictracing, e2fsck, eBPF, ebook, efi, egrep, emacs, encoding, env, error, ess, esx, esxcli, esxi, ethtool, evil, expect, exportfs, factory reset, factory_reset, factoryreset, fail2ban, fbsd, fedora, file, filesystem, find, fio, firewall, firmware, fish, flashrom, forensics, free, freebsd, freedos, fritzbox, fsck, fstrim, ftp, ftps, g-states, gentoo, ghostscript, git, git-filter-branch, github, gitolite, gnutls, gradle, grep, grml, grub, grub2, guacamole, hardware, haskell, hdd, hdparm, hellowor, hex, hexdump, history, howto, htop, htpasswd, http, httpd, https, i3, icmp, ifenslave, iftop, iis, imagemagick, imap, imaps, init, innoDB, inodes, intel, ioncube, ios, iostat, ip, iperf, iphone, ipmi, ipmitool, iproute2, ipsec, iptables, ipv6, irc, irssi, iw, iwconfig, iwlist, iwlwifi, jailbreak, jails, java, javascript, javaws, js, juniper, junit, kali, kde, kemp, kernel, keyremap, kill, kpartx, krypton, lacp, lamp, languages, ldap, ldapsearch, less, leviathan, liero, lightning, links, linux, linuxin3months, lisp, list, livedisk, lmctfy, loadbalancing, locale, log, logrotate, looback, loopback, losetup, lsblk, lsi, lsof, lsusb, lsyncd, luks, lvextend, lvm, lvm2, lvreduce, lxc, lxde, macbook, macro, magento, mailclient, mailing, mailq, manpages, markdown, mbr, mdadm, megacli, micro sd, microsoft, minicom, mkfs, mktemp, mod_pagespeed, mod_proxy, modbus, modprobe, mount, mouse, movement, mpstat, multitasking, myISAM, mysql, mysql 5.7, mysql workbench, mysqlcheck, mysqldump, nagios, nas, nat, nc, netfilter, networking, nfs, nginx, nmap, nocaps, nodejs, numberingsystem, numbers, od, onyx, opcode-cache, openVZ, openlierox, openssl, openvpn, openvswitch, openwrt, oracle linux, org-mode, os, oscilloscope, overview, parallel, parameter expansion, parted, partitioning, passwd, patch, pdf, performance, pfsense, php, php7, phpmyadmin, pi, pidgin, pidstat, pins, pkill, plesk, plugin, posix, postfix, postfixadmin, postgres, postgresql, poudriere, powershell, preview, profiling, prompt, proxmox, ps, puppet, pv, pvecm, pvresize, python, qemu, qemu-img, qm, qmrestore, quicklisp, r, racktables, raid, raspberry pi, raspberrypi, raspbian, rbpi, rdp, redhat, redirect, registry, requirements, resize2fs, rewrite, rewrites, rhel, rigol, roccat, routing, rs0485, rs232, rsync, s-states, s_client, samba, sar, sata, sbcl, scite, scp, screen, scripting, seafile, seagate, security, sed, serial, serial port, setup, sftp, sg300, shell, shopware, shortcuts, showmount, signals, slattach, slip, slow-query-log, smbclient, snmpget, snmpwalk, software RAID, software raid, softwareraid, sophos, spacemacs, spam, specification, speedport, spi, sqlite, squid, ssd, ssh, ssh-add, sshd, ssl, stats, storage, strace, stronswan, su, submodules, subzone, sudo, sudoers, sup, swaks, swap, switch, switching, synaptics, synergy, sysfs, systemd, systemtap, tar, tcpdump, tcsh, tee, telnet, terminal, terminator, testdisk, testing, throughput, tmux, todo, tomcat, top, tput, trafficshaping, ttl, tuning, tunnel, tunneling, typo3, uboot, ubuntu, ubuntu 16.04, udev, uefi, ulimit, uname, unetbootin, unit testing, upstart, uptime, usb, usbstick, utf8, utm, utm 220, ux305, vcs, vgchange, vim, vimdiff, virtualbox, virtualization, visual studio code, vlan, vmstat, vmware, vnc, vncviewer, voltage, vpn, vsphere, vzdump, w, w701, wakeonlan, wargames, web, webdav, weechat, wget, whois, wicd, wifi, windowmanager, windows, wine, wireshark, wpa, wpa_passphrase, wpa_supplicant, x2x, xfce, xfreerdp, xmodem, xterm, xxd, yum, zones, zsh

View posts from 2017-02, 2017-01, 2016-12, 2016-11, 2016-10, 2016-09, 2016-08, 2016-07, 2016-06, 2016-05, 2016-04, 2016-03, 2016-02, 2016-01, 2015-12, 2015-11, 2015-10, 2015-09, 2015-08, 2015-07, 2015-06, 2015-05, 2015-04, 2015-03, 2015-02, 2015-01, 2014-12, 2014-11, 2014-10, 2014-09, 2014-08, 2014-07, 2014-06, 2014-05, 2014-04, 2014-03, 2014-01, 2013-12, 2013-11, 2013-10


Unless otherwise credited all material Creative Commons License by sjas