Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

I am using GNU Emacs 23.2. I would like to bind [Control] to the key ö on my (German) keyboard. That way I can comfortably trigger C- in prefix commands with my right hand. Unfortunately I have no idea how to do so. Emacs's global-set-key does not help here, as pressing C- is not a command.

Update: I am on Win32 and GNU/Linux. I would like to have this binding in emacs only though - achieved with emacs very own means.

share|improve this question
    
What OS are you using? How about performing the keymapping at that level? –  Not Sure Jan 28 '11 at 17:37
    
The more usual approach is to set Caps Lock to Ctrl. That can be done easily with the X11 keyboard option "XkbOptions" "ctrl:nocaps". For Windows you have to import a registry key. Emacs is not the only program in which a convenient Ctrl key is useful. –  ceving Jun 4 '11 at 18:04
add comment

2 Answers 2

What about a Control lock key?

One obstacle for a full equivalent to Control is that it would need to know both when it was held down and when it was released. Emacs keyboard events (unlike mouse events) don't get split into 'down' and 'up' parts, which makes 'released' hard for us to detect there. For example, the only significant difference between C-x C-o and C-x o is the 'control-up' event before the second character. However, that's only a problem if you 'let go' part way through a key sequence

The method here lets you bind any key as Control lock inside Emacs. I've also included some easy work-arounds for key sequences that release the Control key part-way through.


The following code gives you a 'Control Lock' binding, which holds down the modifier for one whole key sequence. The example below binds this to ö, but you can bind it to anything you like.

(defun read-control-sequence (prompt)
  (let (keys)
    (setq extra-keyboard-modifiers ?\C-a)
    (setq keys (read-key-sequence-vector (or prompt "[Control lock]")))
    (setq extra-keyboard-modifiers 0)
    keys))

(define-key key-translation-map [?ö] 'read-control-sequence)

To use this, simply press (and release) ö. The next key will act as if control is pressed. If the key you entered was a prefix key (e.g. you pressed x to get C-x) then control will stay down for the next key, and so on until you press a non-prefix key.

If you use this a lot, you may also want to add bindings in your .emacs for common commands that don't 'let go' of control part way through. For example, this:

(global-set-key (kbd "C-x C-4")
                (lookup-key (current-global-map)
                            (kbd "C-x 4")))

will make all of the commands starting C-x 4 be available at C-x C-4 too, so that typing ö x 4 f will run find-file-other-window.

You might also find it helpful to add a mapping (e.g. to capital Ö) just to provide a standalone C-x:

(define-key key-translation-map [?Ö] [(control ?x)])

All of the above code can be installed (as usual) by adding it to your .emacs file and restarting Emacs, or by typing C-x C-e after each top-level expression. You should find that this approach integrates with the rest of Emacs more or less seamlessly.

share|improve this answer
add comment

Not possible, control is a modifier key and is handled by the operating system/window manager.

See this question on SO: Mapping Caps Lock to Control from within emacs on Windows

share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.