[Top][All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Displaying keyboard diagrams

From: jcg . sturdy
Subject: Displaying keyboard diagrams
Date: Wed, 10 Dec 2008 05:15:05 -0800 (PST)
User-agent: G2/1.0

Here's a code fragment to pop up a keyboard diagram whenever you
switch to certain input methods (such as ones whose layout you're not
familiar with).  The keys for each hand are coloured differently, to
make it easier to locate a key (particularly if you touch-type and/or
use a split keyboard).

(defvar input-methods-wanting-diagrams
  '("mongolian-cyrillic" "russian-computer")
  "Input methods for which I'd like diagrams displayed.")

(defun quail-keyboard-show-hands-row (left-keys right-letters)
  "Colour the background of LEFT-KEYS and RIGHT-LETTERS in this row."
  (let* ((row-start (point))
         (row-middle (search-forward "|"
                                     (point-max) t left-keys))
         (row-letters-end (search-forward "|"
                                          (point-max) t right-letters))
         (row-end (line-end-position)))
    (put-text-property row-start row-middle
                       'face (cons 'foreground-color "red"))
    (put-text-property row-middle row-letters-end
                       'face (cons 'foreground-color "blue"))
    (put-text-property row-letters-end row-end
                       'face (cons 'foreground-color "dark green"))))

(defvar quail-keyboard-layout-hand-rows-alist
  '(("standard" (6 5) (6 5) (6 4) (6 2)))
  "How many left-hand keys and right-hand letters there are for each
This is an alist with an entry for each keyboard type.")

(defun quail-show-keyboard-layout-compactly ()
  "Show the physical layout of the current keyboard type.
The variable `quail-keyboard-layout-type' holds the currently selected
keyboard type."
  (let ((layout (assoc quail-keyboard-layout-type
    (or layout
        (error "Unknown keyboard type: %s"
    (let ((bufname "*Keyboard layout*"))
      (with-output-to-temp-buffer bufname
        (with-current-buffer standard-output
          (insert "Keyboard layout (keyboard type: "
          (quail-insert-kbd-layout (cdr layout))))
      (set-buffer bufname)
      (let ((inhibit-read-only t)
             (cdr (assoc quail-keyboard-layout-type
        (goto-char (point-min))
        (search-forward "+")
        (beginning-of-line 2)
        (dolist (row layout-data)
          (apply 'quail-keyboard-show-hands-row row)
          (beginning-of-line 3))))))

(defun jcgs-input-method-activate-hook ()
  "Show stuff concerning the new input method."
  (if (member current-input-method input-methods-wanting-diagrams)
    (let ((buffer (get-buffer "*Keyboard layout*")))
      (message "got buffer %s" buffer)
      (when buffer
        (let ((window (get-buffer-window buffer)))
          (message "got window %s" window)
          (when window
            (delete-window window)))))))

(add-hook 'input-method-activate-hook

reply via email to

[Prev in Thread] Current Thread [Next in Thread]