Showing posts with label Keyboard. Show all posts
Showing posts with label Keyboard. Show all posts

2021-01-20

Remap one key to another in Windows, like Capslock to Control

There's three options to consider for remapping keys on Windows.

(1) Manually edit the Windows Registry

You can directly edit the Windows registry to remap keys, for example to Map capslock to control.  You'll need to know the keyboard hex scan codes involved though.

(2) Edit the Windows Registry with SharpKeys

If you have many keys to remap, or don't want to manually mess with the registry, there's an App for that!  SharpKeys looks pretty good.  You can use it to remap the Right Alt to the Left Windows key for example.

(3) Don't edit the Registry but run a background app like PT or AHK

Some common remappings like Capslock to control can be easily done without editing the registry at all!  You can run an app that stays in the background, listening for the keys you want changed, then they'll inject the key you want for it to change to.

Microsoft's PowerToys has a module for that sort of usage, and it comes with other toys like advanced file name changer, etc.  The kind of key remapping allowed is extremely limited though.

Another option is AutoHotKey (AHK).  It'll give you extreme customization beyond remapping a single key to a single key.  It'll let you script keys and combos to do pretty much arbitrary things to the keyboard and mouse.

Don't run both PowerToys keyboard remapping module and AHK key remappings together as they may interfere with each other!

(NEW!)  Check out kinto if you're interested in mac-style hotkeys on Linux and Windows!

 

Remap Capslock to Control with AutoHotKey

Make a text file and copy the script below into it, then save the text file with a .ahk file extension.  Double click the .ahk script file and AutoHotKey will run it to give you this 3FTD behaviour.

If you want the script to run every time you log in to Windows, you'll need to move the script or add a shortcut to it into the Windows startup folder.  See detailed instructions for that.

CapslockAsControl.ahk

#NoEnv  ; Recommended for performance and compatibility with future AutoHotkey releases.
; #Warn  ; Enable warnings to assist with detecting common errors.
SendMode Input  ; Recommended for new scripts due to its superior speed and reliability.
SetWorkingDir %A_ScriptDir%  ; Ensures a consistent starting directory.

#SingleInstance force

Capslock::Ctrl



Limitations to all methods

Some Windows hotkeys cannot be remapped!

Key combos like Windows key + L are dealt with by the Windows OS at a much lower level and treated specially.  Those cannot be remapped by PowerToys or AHK, at least not normally or usefully.

You could disable Win+L completely by disabling the Windows lock screen function [1].  But then your computer will never lock... ever.  Not when waking from sleep, not from the Control + Alt + Delete menu.  It's all or nothing.

Some apps don't allow / respect the remappings

Also apps that access the keyboard at a lower level, like some games and VirtualBox, don't play nice with AHK remappings.

Games access keyboards in a way that reduces latency to increase gaming responsiveness. And some games have anti-scripting functionality to discourage cheating.

VirtualBox is virtualizing your PC for another OS so a Windows background app messing with the keyboard of course won't play nice with VirtualBox.  And yes, Win+L will lock Windows even if you're inside a Linux guest in VirtualBox!

Vendor hotkeys can't be remapped

There are vendor specific keys and combos that your PC maker may have added via their keyboard drivers.  Like Lenovo's Fn+Tab starts the Windows magnifier key combo.  Press that while in a VirtualBox guest OS and it'll still run the magnifier!

Neither AHK nor PowerToys can remap the Fn+Tab combo either.  In fact, remapping the Fn key is usually tough if not impossible.  It's something handled specially by vendor's drivers on laptops to provide special functionality.

 

 

Compared to Macs

Scripting with AppleScript

Coming from the Mac world where AppleScript lets you implement customized and scripted automation of tasks, AutoHotKey (AHK) is similar in many ways.  Since AppleScript can be substituted with JavaScript, then the scripting language itself is better than AHK.

However, AppleScript doesn't provide hooks to customize or remap keys and key combos, so AHK does have this feature AppleScript doesn't.

On the flip side, Mac apps that make extensive use of Apple's Open Scripting Architecture allow AppleScripts to directly access certain data inside those apps for better integration.  Not every or many apps support advanced OSA usage, but it gives AppleScript an edge.

Remapping with Karabiner

As for providing key and combo remapping, I'm finding Karabiner-Elements on Macs to be better for that job than AHK.

Karabiner is more intuitive, purpose built for remapping keys, with many of the same AHK features for multi-key remapping.  It can also run scripts on key triggers like AHK, so Karabiner + AppleScript is roughly equivalent to AHK's functionality.

Less limitations

Macs have less limitations than Windows on the key remapping front too.  You'll have no problems using Karabiner-Elements to remap the "Apple key" (command key) vs the difficulties of remapping the Windows key (especially special combos like Win+L).

Key remappings with Karabiner on Macs are also respected by VirtualBox unlike remappings done via AHK on Windows.  To be fair, some AHK key remappings do work with VirtualBox, but I had trouble with modifier keys and special Windows hotkeys.


References

[1] How to disable Windows 10 Workstation Lock (Window + L) Functionality

2011-04-09

Few notes on ergonomic keyboards and mouse

I'm typing away at a lot of software programming and thesis writing, so having a good keyboard is a must. Here's two suggestions, both of which I've personally tried and has worked well for me. I wrote down a few notes for you to ponder.


Currently, I use a Microsoft Comfort Curve Keyboard 2000. It's an ergonomic keyboard with a soft curve laterally, and no vertical curve (it lays flat). It's a wicked keyboard if your shoulder width is not so wide, because it has only that slight curve, rather than the dramatic curve of other ergonomic keyboards.  It also has a light but distinctive touch, so it's easy to press the key down, but not so easy that you would accidentally "smoosh" a key down by accident.  The key's travel — how far it travels from the start of pressing a key to bottoming out — is also quite short, so there's less finger motion required to type.

If the Comfort Curve 2000 doesn't fit your body type, you might want to try the Microsoft Natural Ergonomics Keyboard 4000.  I've used that one before, and it's pretty good, but only if your shoulder width is wider than, well, mine is.  Unfortunately, it's keys have a longer travel length, and its spacebar is a tad heavy to press down due to its design. If you're not used to the keyboard, your fingers may become tired and sore the first few times of prolonged usage, but at least for me, I get used to it soon after.  I've used that for years before switching to the Comfort Curve 2000 model, and it was a good experience.

Unfortunately, both of those keyboards, at least when used on a Mac, optionally suggests that you install the Microsoft IntelliType software. The IntelliType software has been known to apparently cause a lot of kernel panics for on Mac OS X — on the order of once or twice a day even, when under heavy typing load. If you use Windows, then this is not an issue (I've used both of those keyboards under Windows XP and Windows 7, and they work well). If you use a Mac, you may find my previous post on the issue useful.

2011-04-08

Mac OS X Kernel Panics due to Microsoft IntelliType: Solution

It seems all evidence [1] points to Microsoft IntelliType causes kernel panics on Macs.  This seems to be a problem that has existed for a long while, from IntelliType versions 7 at least up to 8, and Mac OS X from 10.5 at least up to 10.6.


I learned this the hard way, having bought a Microsoft Comfort Curve 2000 ergonomic keyboard. That's a wicked keyboard, by the way, if your shoulder width is not so wide, because it has only a slight curve, rather than the dramatic curve of other ergonomic keyboards.  It also has a light but distinctive touch, so it's easy to press the key down, but not so easy that you would accidentally "smoosh" a key down by accident.  The key's travel is also quite short, so it's less finger motion required to type.

Unfortunately, installing the IntelliType software seems to have caused kernel panics for my MacBook Pro on the order of once or twice a day (under heavy typing load.  That meant I lost a lot of programming and typing of emails and reports.  sigh

The solution is simple: uninstall IntelliType.  The uninstaller is in the Utilities folder in the Applications folder.  But that's not a very good solution by itself, because the Command/"Apple" and Option keys are reversed on Microsoft keyboards compared to Mac keyboards.  So here's the other half of the solution: