5

I've developped a case of emacs pinky from pressing C-x too much. Ideally, I would like to use the space bar instead of control as a prefix command since it is much easier to press and hold with the thumb. Pressing and releasing space should still add a space but pressing Space+x simultaneously should be bindable to a command. For example:

(local-set-key (kbd "SPC-s") 'search-forward)

Does anyone have any ideas on how this could be implemented? Is it possible to do it using only elisp or would I have to modify the emacs source and compile my own version?

I would prefer a solution which is OS independent since I use emacs on both Windows and Linux.

EDIT: I have tried key-chord.el which helps in some cases but not all (C-x C-s). I would prefer a minor mode such as holding-space-is-control or holding-space-is-meta

EDIT: Thanks for all the replies. I'm currently using key-chord to map many C-* command to j* or f* depending on if * is a left or right hand key. For example, I've replace C-x b with jb. It works fine for all commands you typically type once but not for commands you use repeatedly (such as forward or backward-paragraph). It is the best cross-platform solution so far since it only requires a custom .emacs and the key-chord.el file. I would prefer a solution which requires less remapping and reduces the risk of typing "fyi" and getting "< yank >i". I believe using space could work but I don't know enough about the technical details of emacs to make it work.

I've considered replacing Caps-Lock or Alt with Ctrl but that only helps for the left pinky. Many common commands are executed using the right pinky (C-x, C-s, C-w, C-y).

athoren
  • 443
  • 4
  • 12
  • 2
    One trick I've found is that (keyboard permitting) you can rest part of your hand to hit the ctrl key and use your thumb to hit the keys such as C-x C-s. The Caps Lock remapping works too as you can just use your ring finger. Although my personal favorite is switch ALT and CTRL the reason is because most keyboards before actually had the keys like that (ALT is used less typically than CTRL) so you would use your thumb instead, this takes some getting used to and assumes you use ALT a lot less than CTRL. – Jesus Ramos Jan 04 '12 at 12:23
  • I've tried using my lower palm for holding Ctrl but it wasn't easy due to the small size of the key on my MS Natural Keyboard. If I could find a keyboard with HUGE ctrl buttons, I'd buy a couple. I've looked at the Kinesis and Maltron keyboards but they're rather expensive. I would also prefer a solution which was more portable than carrying around your own keyboard :) – athoren Jan 04 '12 at 14:57
  • For me the switching CTRL and ALT works, traditional old keyboards were actually this way by default which is why Emacs pinky was never really a problem. – Jesus Ramos Jan 04 '12 at 15:01
  • I haven't tried it yet but it is a good idea. I've heard the old keyboards were like that. Unfortunately, on windows it requires installation of drivers which means I have to ask my IT department for permission (maybe there are other ways?). – athoren Jan 04 '12 at 15:08
  • There are some registry keys you can change (at least that's how I did it) unfortunately cant' remember which those are right now :( – Jesus Ramos Jan 04 '12 at 15:23

10 Answers10

6

I remapped my CapsLock to Control to avoid the pain (using KDE to do the mapping, not emacs, though).

Update: I was able to do that in LXDE and MS Windows, too.

choroba
  • 231,213
  • 25
  • 204
  • 289
6

On Windows, AutoHotKey is a very flexible and scriptable solution for most kinds of key remapping requirements.

phils
  • 71,335
  • 11
  • 153
  • 198
5

I do not think this is possible in Emacs Lisp. For doing what you want, one would have to check whether the 'space' key is still held down or if it was released. However, keyboard events in Emacs are simply characters, not 'pressed' and 'released' events like for mouse buttons. I don't know enough about the Emacs C code to say whether this could be implemented there without breaking the normal event loop.

So let's turn to OS-dependent solutions. Under Xorg, you can map modifiers to normal keys (using xmodmap); however, pressing 'space' would still generate a whitespace while also working as a modifier, which is not what you want. The only solution I know of is a special Xorg keyboard driver:

https://gitlab.com/at-home-modifier/at-home-modifier-evdev/wikis/home

I don't know if something similar exists for Windows, though.

teika kazura
  • 1,348
  • 1
  • 16
  • 21
pokita
  • 1,241
  • 10
  • 12
  • Windows is the main issue since I work in windows. Writing custom keyboard drivers in win seem to be much more difficult than in linux. I feared there was no 'pressed' event in elisp since I've never seen anything like it. I still hope it may be possible in the Emacs sources though. – athoren Jan 04 '12 at 15:28
  • The at-home-modifier seem like a good solution on Linux. If I could find something similar on windows I'd be very happy... – athoren Jan 04 '12 at 15:36
  • With AutoHotKey, answered by phils, you can do it. (I'm the author of at-home-modifier. =) Good luck. – teika kazura Feb 28 '12 at 11:48
4

Xah Lee has wrote a nice article on this subject, especially when he recommends to

use your palm or semi-fist instead of your pinky to press the control key

Glorfindel
  • 21,988
  • 13
  • 81
  • 109
Daimrod
  • 4,902
  • 23
  • 25
  • 2
    It's far better to [use the space key both as space and ctrl](http://stackoverflow.com/a/8935973/780703). Ctrl is crucial to Emacs, and it's too clumsy to press Ctrl with your palm. I use the left bottom key for window management. – teika kazura Oct 17 '12 at 05:49
4

This should do what you want:

http://www.emacswiki.org/emacs/space-chord.el

(space-chord-define-global "s" 'search-forward)

It does "chording" so you'll have to type space and s at the same time, but doing so is easy.

Or, if you could use control-lock to help avoid holding down control as much (it's like caps lock for the control key).

trogdoro
  • 49
  • 1
2

Over the last several weeks I have written and used an AutoHotKey script that provides Windows-wide functionality to do exactly what you have described. It is now available on GitHub. While it is not an OS independent solution, there are nearly identical implementations on Linux (e.g. At-Home-Modifier and Space2Ctrl) so you should be able to have the same user experience on either platform. On the plus side you also get to use it in other programs for tasks like copying, pasting and switching browser tabs. Hope it helps.

Ben
  • 158
  • 2
  • 10
1

the exact solution is described here. it consists of using an extra software (available on each os). http://emacswiki.org/emacs/MovingTheCtrlKey#toc24

nasske
  • 19
  • 1
  • that's about moving/swaping ctrl to caps-lock. The space key is actually very different in this respect. – Slava Oct 08 '20 at 13:20
1

What I do is switch alt keys for controls and super keys for alt-meta, this avoids clicking the annoying left control. Besides I switch Caps Lock for Hyper to have an extra modifier that I use for switching between buffers H-p H-n and other stuff. If you have Ubuntu the change is trivial in your keyboard settings.

Jorge
  • 11
  • 1
1

You can look at cua-mode which does something similar for C-x and C-c (when mark is active). I'm certainly no expert (I don't even use cua-mode), but looking briefly at the code there is a timer which sends a timeout event so that (in your case) you would bind [?\s timeout] to insert a space and bind other keys to whatever you want. You also can't (I don't think) bind keys as if SPC were a modifier:

(local-set-key (kbd "SPC-s") 'search-forward)

but you would bind them as (say)

(define-key space-as-prefix-map (kbd "s") 'search-forward)

I tried to do a quick test using cua-mode, but unfortunately, the timer only runs when the mark is active. Well, it's a little more complicated than that but suffice it to say that I didn't persevere long enough to figure it all out. But it's definitely possible to make space be to control what escape is to meta.

Ivan Andrus
  • 5,221
  • 24
  • 31
0

This isn't an answer to your question but it is a way to avoid the Emacs pinky: don't use one hand to press modifiers and a key. So (assuming you have a Qwerty keyboard) use your right hand to press Control and your left hand to press the 'x'.

aerique
  • 982
  • 5
  • 21
  • 1
    I started doing that when I first felt the pain and now I have a pain in both pinkies :) The best solution I've found so far is key-chord. For example, I use 'jb' instead of 'C-x b'. However, it doesn't work very well for repeated commands such as 'move 4 lines up' (5 x C-p). – athoren Jan 04 '12 at 15:32