1

On Emacs, Italian keyboard, I'd like the alphanumeric keys above the alphabet (1/!, 2/", 3/£, 4/$, ...) to insert the shifted character (e.g. ! " £ $) when pressed alone. Is there a way to do that?

4

3 回答 3

4

For each number/char pair, you'll need to install two key bindings to swap them, and a third one to avoid messing up the keypad (since the kp-0-kp-9 keys are translated to 0-9, but I guess you don't want kp-1 to insert !)

Here is a macro to avoid creating all those key bindings by hand:

(defmacro swap-keys (list)
  `(progn
     ,@(mapcar
        (lambda (keys)
          (let ((key1 (car keys))
                (key2 (cdr keys)))
            `(progn
               (global-set-key ,key1 (lambda () (interactive) (insert ,key2)))
               (global-set-key ,key2 (lambda () (interactive) (insert ,key1)))
               (global-set-key (kbd ,(format "<kp-%s>" key1))
                               (lambda () (interactive) (insert ,key1))))))
        list)))

(swap-keys (("1" . "!")
            ("2" . "\"")))
于 2013-01-05T13:35:30.963 回答
4

You can set up a custom input method that has those keys flipped (doc).

ex I have this in my .emacs for the layout I use:

(eval-after-load 'quail
  '(progn
      (add-to-list 'quail-keyboard-layout-alist
     '("us-pgr-dvk" . "\
                              \
$~&%[7{5}3(1=9*0)2+4]6!8#`    \
  ;:,<.>pPyYfFgGcCrRlL/?@^\\|  \
  aAoOeEuUiIdDhHtTnNsS-_      \
  '\"qQjJkKxXbBmMwWvVzZ        \
                              "))
   ))
(quail-set-keyboard-layout "us-pgr-dvk")
于 2013-01-05T17:06:24.980 回答
1

You can write:

(global-set-key (kbd "1") (lambda () (interactive) (insert "!")))

etc.

于 2013-01-05T12:26:38.753 回答