1 ;;; hmouse-mod.el --- Action Key acts as CONTROL modifier and Assist Key as META modifier.
3 ;; Copyright (C) 1992-1995 Free Software Foundation, Inc.
4 ;; Developed with support from Motorola Inc.
6 ;; Author: Bob Weiner, Brown U.
7 ;; Maintainer: Mats Lidell <matsl@contactor.se>
8 ;; Keywords: hypermedia, mouse
10 ;; This file is part of GNU Hyperbole.
12 ;; GNU Hyperbole is free software; you can redistribute it and/or
13 ;; modify it under the terms of the GNU General Public License as
14 ;; published by the Free Software Foundation; either version 3, or (at
15 ;; your option) any later version.
17 ;; GNU Hyperbole is distributed in the hope that it will be useful,
18 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
19 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
20 ;; General Public License for more details.
22 ;; You should have received a copy of the GNU General Public License
23 ;; along with GNU Emacs; see the file COPYING. If not, write to the
24 ;; Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
25 ;; Boston, MA 02110-1301, USA.
29 ;; This module is meant to be used with a chord keyboard in one hand for
30 ;; typing and a mouse in the other. It requires that Hyperbole be loaded
31 ;; in order to work. Hyperbole defines two Smart Keys, the Action Key and
32 ;; the Assist Key, on the middle and right buttons by default.
34 ;; If the Action Key is held down while alpha characters are typed,
35 ;; they are translated into Control keys instead. The Assist
36 ;; Key translates them into Meta keys. When both Smart Keys
37 ;; are depressed, Control-Meta keys are produced. The commands bound
38 ;; to the characters produced are then run.
40 ;; So the Smart Keys modify the keys typed, e.g. Action Key + {a}
41 ;; runs the function for {C-a}.
43 ;; If no keys are typed while the Smart Keys are down, they operate as
44 ;; normally under Hyperbole.
48 ;; (hmouse-mod-set-global-map)
54 ;;; Other required Elisp libraries
63 (defvar hmouse-mod-global-map nil
64 "Global key map installed by hmouse-mod-set-global-map function.
65 Translates self-insert-command characters into control and meta characters if
66 the Action or Assist Keys are depressed at the time of key press.")
72 (defun hmouse-mod-insert-command (count)
73 "Surrogate function for self-insert-command. Accounts for modifier Smart Keys."
75 (if (and (boundp 'action-key-depressed-flag)
76 (boundp 'assist-key-depressed-flag))
77 (cond ((and action-key-depressed-flag assist-key-depressed-flag)
78 (setq action-key-cancelled t
79 assist-key-cancelled t)
80 (let* ((c (downcase last-command-char))
81 (key (char-to-string (+ 128 (% (- c ?\`) 128)))))
82 (if (and (or (= c ?\C-@)
84 (hmouse-mod-execute-command key)
88 (action-key-depressed-flag
89 (setq action-key-cancelled t)
90 (let ((c (downcase last-command-char)))
91 (if (and (or (= c ?\C-@)
93 (hmouse-mod-execute-command
94 (char-to-string (- c ?\`)))
98 (assist-key-depressed-flag
99 (setq assist-key-cancelled t)
100 (hmouse-mod-execute-command
101 (char-to-string (+ 128 (% last-command-char 128))))
103 (t (call-interactively 'self-insert-command)))
104 (call-interactively 'self-insert-command))
107 (defun hmouse-mod-keyboard-quit ()
108 "Surrogate function for keyboard-quit. Cancels any hmouse-mod-prefix."
110 (setq hmouse-mod-prefix nil)
113 (defun hmouse-mod-set-global-map ()
114 "Creates 'hmouse-mod-global-map' and installs as current global map.
115 It accounts for modifier Smart Keys."
117 (setq hmouse-mod-global-map (copy-keymap global-map))
118 (substitute-key-definition
119 'self-insert-command 'hmouse-mod-insert-command hmouse-mod-global-map)
120 (substitute-key-definition
121 'keyboard-quit 'hmouse-mod-keyboard-quit hmouse-mod-global-map)
122 (use-global-map hmouse-mod-global-map))
125 ;;; Private functions
128 (defun hmouse-mod-execute-command (key)
129 "Executes command associated with keyboard KEY or if KEY prefix, records it."
130 (setq key (concat hmouse-mod-prefix key))
131 (let ((binding (key-binding key)))
132 (cond ((and (not (or (vectorp binding) (stringp binding)))
134 (if (> (length key) 1)
135 (or noninteractive (message (key-description key))))
136 (setq hmouse-mod-prefix nil)
137 (call-interactively binding))
139 (setq hmouse-mod-prefix nil)
140 (error "(hmouse-mod-execute-command): {%s} not bound to a command."
141 (key-description key)))
143 (setq hmouse-mod-prefix nil)
144 (error "(hmouse-mod-execute-command): {%s} invalid key sequence."
145 (key-description key)))
146 (t (or noninteractive (message (key-description key)))
147 (setq hmouse-mod-prefix key)))))
150 ;;; Private variables
153 (defvar hmouse-mod-prefix nil
154 "Prefix key part of current key sequence.")
156 (provide 'hmouse-mod)
158 ;;; hmouse-mod.el ends here