One way to reduce repetitive-strain injury from Emacs is to avoid pressing two keys simultaneously with the same hand. That is, avoid using modifier keys. For C-KEY, use one hand for KEY and the other for Ctrl. For M-KEY, do similarly as for C-KEY, or press and release Esc and then press KEY. And of course, take advantage of the automatic indenting and other features of Emacs that save keystrokes.
In this same line of thought try out
(setq modifier-keys-are-sticky t). From the documentation, “This means that you can release the modifier key before pressing down the key that you wish to be modified. Although this is non-standard behavior, it is recommended because it reduces the strain on your hand, thus reducing the incidence of the dreaded Emacs-pinky syndrome.”
Unfortunately, this cool feature isn’t implemented in GNU Emacs.
GNU Emacs-21.3 seem to support sticky modifier keys - SureshKolla?
How does GNU Emacs-21.3 support sticky modifier keys? Can’t find it in my copy. -Benjamin Rutt
On Windows, I found a way to set <lwindow>, <rwindow> and <apps> as sticky modifiers, without OS settings:
(setq w32-pass-lwindow-to-system nil) ;; prevent single keypress from activating Start Menu (setq w32-lwindow-modifier 'nil) ;; make sure it's not used as a modifier (define-key key-translation-map (kbd "<lwindow>") 'event-apply-super-modifier) (define-key key-translation-map (kbd "<apps>") 'event-apply-alt-modifier) (global-set-key (kbd "s-k") 'kill-whole-line)
now you can press <lwindow> and (after releasing <lwindow>) then
‘k’ to kill the whole line. And in this way, you can use those
‘system hotkeys’ (such as win+r, win+l) in emacs and Windows at the same time. – BaManzi
On MS Windows it is the operating system that implements this feature for any application. It is in the Control Panel under Accessability Options and is called StickyKeys, see Accessibility Tutorials for Windows.
Turning “Sticky Keys” on in the Macintosh is extremely easy (OSX 10.4.4). One goes to “Universal Access” in “System Preferences” and selects “Keyboard” in the horizontal menu across the top of the screen. It is self-explanatory from there on. (Citing a message from John Gage on emacs-nxml-mode list.)
For Linux console you can use
kbd package to set Control, Alt and Shift keys to SCtrl, SAlt, SShift keycodes. See e.g. Keyboard and Console HOWTO: 15. Examples of use of loadkeys and xmodmap.
X.org provides sticky keys support via so-called “AccessX” functionality in the XKB (XKeyboard) module bundled with X.org. GNOME and KDE both provide GUI interfaces for viewing and modifying AccessX settings, as described below. Lighter-weight window managers (e.g., FVWM, IceWM, Sawtooth), however, do not; users of these window managers must use a CLI interface instead, as described below. (Of course, some may view this as an advantage!)
xkbset is a CLI interface to AccessX and other XKB-specific functionality. It’s quite helpful – though a tad oddly documented.
Debian users install
apt-get install xkbset
Gentoo and Exherbo install
xkbset by first downloading this ebuild, moving it into a local overlay, regenerating that local overlay’s cache (…beyond the scope of this page), and:
paludis --install xkbset
After installation, run
xkbset h to display help for all options,
xkbset q to display all current options, and
xkbset q exp to display all current expiration settings.
Now, temporarily enable sticky keys for the current X.org session via:
# Enable "sticky keys" for all modifier keys, while also enabling "latchlock" # (i.e., pressing any modifier key twice in a row locks that key # on) and disabling "twokey" (i.e., pressing any modifier key and another key # at the same time permanently disables "sticky keys"). Note that enabling # "sticky" automatically enables sticky keys for Apple- and Windows-specific # modifier keys as well, including: <Shift>, <Ctrl>, <Alt>, <Fn>, and <Apple>. xkbset -bell -feedback sticky -twokey latchlock # Disable expiration of "sticky keys" after the specified time in seconds. When # expiration is enabled, sticky keys are permanently disabled after that many # seconds. This is quite unhelpful. xkbset exp 64 '=sticky' '=twokey' '=latchlock'
If that works, permanently enable sticky keys for all X.org sessions by placing the above two commands in your user-local X.org autostart file, ~/.xinitrc.
Gnome 2.0 implements this; use
gnome-control-center to configure. You can find more information at The GNOME Accessibility Project.
I found the following settings to my liking within GNOME 2.14.3 on Ubuntu Dapper Drake:
Turning off repeat keys has the unfortunate side effect of making it difficult to delete text in programs other than Emacs or Vim, but it thankfully prevents that annoying dialog box from popping up when you hold one of the modifier keys down for too long. Unchecking “disable if two keys pressed together” makes it so that you can hold down a modifier key and hit a key without being accosted by the exact same dialog box.
One thing I found lacking in the documentation was that pressing a modifier key twice turned it on indefinitely until the same modifier key was pressed again. Nice to know.
KDE also implements this; find “Regional & Accessibility > Accessibility > Keyboard” in KControl. You can find more information at KDE Accessibility Project
The underlying API-level framework is called MSAA on MS Windows and ATK in GNOME. The applications have to use this to support Sticky Modifiers (and a lot of other accessiblity options). In some cases this is very simple due to the way the frameworks are built.
On MS Windows the support is simply built into the newer widgets so if you use those you get it for nothing
Some people might find the comment at the end of AlexSchroeder home page useful.
I recommend trying out sticky keys if your OS supports it, because your hands really feels better. It takes a while to switch mindset e.g. from M-x to M x (pressing one after the other), but it’s worth it. No less effective and less stress in the hands.