comparison lispref/commands.texi @ 72212:c6f585c55a73

Update xrefs. (Event Mod): New node, cut out from old Translating Input.
author Richard M. Stallman <rms@gnu.org>
date Mon, 31 Jul 2006 18:41:58 +0000
parents 87425e2757e0
children 705d28578f2d 858cb33ae39d
comparison
equal deleted inserted replaced
72211:c2484c5211e4 72212:c6f585c55a73
1085 terminal can distinguish between them, Emacs conveys the distinction to 1085 terminal can distinguish between them, Emacs conveys the distinction to
1086 Lisp programs by representing the former as the integer 9, and the 1086 Lisp programs by representing the former as the integer 9, and the
1087 latter as the symbol @code{tab}. 1087 latter as the symbol @code{tab}.
1088 1088
1089 Most of the time, it's not useful to distinguish the two. So normally 1089 Most of the time, it's not useful to distinguish the two. So normally
1090 @code{function-key-map} (@pxref{Translating Input}) is set up to map 1090 @code{function-key-map} (@pxref{Translation Keymaps}) is set up to map
1091 @code{tab} into 9. Thus, a key binding for character code 9 (the 1091 @code{tab} into 9. Thus, a key binding for character code 9 (the
1092 character @kbd{C-i}) also applies to @code{tab}. Likewise for the other 1092 character @kbd{C-i}) also applies to @code{tab}. Likewise for the other
1093 symbols in this group. The function @code{read-char} likewise converts 1093 symbols in this group. The function @code{read-char} likewise converts
1094 these events into characters. 1094 these events into characters.
1095 1095
2049 @code{read-key-sequence}, which uses @code{read-event}. These and other 2049 @code{read-key-sequence}, which uses @code{read-event}. These and other
2050 functions for event input are also available for use in Lisp programs. 2050 functions for event input are also available for use in Lisp programs.
2051 See also @code{momentary-string-display} in @ref{Temporary Displays}, 2051 See also @code{momentary-string-display} in @ref{Temporary Displays},
2052 and @code{sit-for} in @ref{Waiting}. @xref{Terminal Input}, for 2052 and @code{sit-for} in @ref{Waiting}. @xref{Terminal Input}, for
2053 functions and variables for controlling terminal input modes and 2053 functions and variables for controlling terminal input modes and
2054 debugging terminal input. @xref{Translating Input}, for features you 2054 debugging terminal input.
2055 can use for translating or modifying input events while reading them.
2056 2055
2057 For higher-level input facilities, see @ref{Minibuffers}. 2056 For higher-level input facilities, see @ref{Minibuffers}.
2058 2057
2059 @menu 2058 @menu
2060 * Key Sequence Input:: How to read one key sequence. 2059 * Key Sequence Input:: How to read one key sequence.
2061 * Reading One Event:: How to read just one event. 2060 * Reading One Event:: How to read just one event.
2061 * Event Mod:: How Emacs modifies events as they are read.
2062 * Invoking the Input Method:: How reading an event uses the input method. 2062 * Invoking the Input Method:: How reading an event uses the input method.
2063 * Quoted Character Input:: Asking the user to specify a character. 2063 * Quoted Character Input:: Asking the user to specify a character.
2064 * Event Input Misc:: How to reread or throw away input events. 2064 * Event Input Misc:: How to reread or throw away input events.
2065 @end menu 2065 @end menu
2066 2066
2086 Otherwise, it returns a vector, since a vector can hold all kinds of 2086 Otherwise, it returns a vector, since a vector can hold all kinds of
2087 events---characters, symbols, and lists. The elements of the string or 2087 events---characters, symbols, and lists. The elements of the string or
2088 vector are the events in the key sequence. 2088 vector are the events in the key sequence.
2089 2089
2090 Reading a key sequence includes translating the events in various 2090 Reading a key sequence includes translating the events in various
2091 ways. @xref{Translating Input}. 2091 ways. @xref{Translation Keymaps}.
2092 2092
2093 The argument @var{prompt} is either a string to be displayed in the 2093 The argument @var{prompt} is either a string to be displayed in the
2094 echo area as a prompt, or @code{nil}, meaning not to display a prompt. 2094 echo area as a prompt, or @code{nil}, meaning not to display a prompt.
2095 The argument @var{continue-echo}, if non-@code{nil}, means to echo 2095 The argument @var{continue-echo}, if non-@code{nil}, means to echo
2096 this key as a continuation of the previous key. 2096 this key as a continuation of the previous key.
2288 @defvar num-nonmacro-input-events 2288 @defvar num-nonmacro-input-events
2289 This variable holds the total number of input events received so far 2289 This variable holds the total number of input events received so far
2290 from the terminal---not counting those generated by keyboard macros. 2290 from the terminal---not counting those generated by keyboard macros.
2291 @end defvar 2291 @end defvar
2292 2292
2293 @node Event Mod
2294 @subsection Modifying and Translating Input Events
2295
2296 Emacs modifies every event it reads according to
2297 @code{extra-keyboard-modifiers}, then translates it through
2298 @code{keyboard-translate-table} (if applicable), before returning it
2299 from @code{read-event}.
2300
2301 @c Emacs 19 feature
2302 @defvar extra-keyboard-modifiers
2303 This variable lets Lisp programs ``press'' the modifier keys on the
2304 keyboard. The value is a character. Only the modifiers of the
2305 character matter. Each time the user types a keyboard key, it is
2306 altered as if those modifier keys were held down. For instance, if
2307 you bind @code{extra-keyboard-modifiers} to @code{?\C-\M-a}, then all
2308 keyboard input characters typed during the scope of the binding will
2309 have the control and meta modifiers applied to them. The character
2310 @code{?\C-@@}, equivalent to the integer 0, does not count as a control
2311 character for this purpose, but as a character with no modifiers.
2312 Thus, setting @code{extra-keyboard-modifiers} to zero cancels any
2313 modification.
2314
2315 When using a window system, the program can ``press'' any of the
2316 modifier keys in this way. Otherwise, only the @key{CTL} and @key{META}
2317 keys can be virtually pressed.
2318
2319 Note that this variable applies only to events that really come from
2320 the keyboard, and has no effect on mouse events or any other events.
2321 @end defvar
2322
2323 @defvar keyboard-translate-table
2324 This variable is the translate table for keyboard characters. It lets
2325 you reshuffle the keys on the keyboard without changing any command
2326 bindings. Its value is normally a char-table, or else @code{nil}.
2327 (It can also be a string or vector, but this is considered obsolete.)
2328
2329 If @code{keyboard-translate-table} is a char-table
2330 (@pxref{Char-Tables}), then each character read from the keyboard is
2331 looked up in this char-table. If the value found there is
2332 non-@code{nil}, then it is used instead of the actual input character.
2333
2334 Note that this translation is the first thing that happens to a
2335 character after it is read from the terminal. Record-keeping features
2336 such as @code{recent-keys} and dribble files record the characters after
2337 translation.
2338
2339 Note also that this translation is done before the characters are
2340 supplied to input methods (@pxref{Input Methods}). Use
2341 @code{translation-table-for-input} (@pxref{Translation of Characters}),
2342 if you want to translate characters after input methods operate.
2343 @end defvar
2344
2345 @defun keyboard-translate from to
2346 This function modifies @code{keyboard-translate-table} to translate
2347 character code @var{from} into character code @var{to}. It creates
2348 the keyboard translate table if necessary.
2349 @end defun
2350
2351 Here's an example of using the @code{keyboard-translate-table} to
2352 make @kbd{C-x}, @kbd{C-c} and @kbd{C-v} perform the cut, copy and paste
2353 operations:
2354
2355 @example
2356 (keyboard-translate ?\C-x 'control-x)
2357 (keyboard-translate ?\C-c 'control-c)
2358 (keyboard-translate ?\C-v 'control-v)
2359 (global-set-key [control-x] 'kill-region)
2360 (global-set-key [control-c] 'kill-ring-save)
2361 (global-set-key [control-v] 'yank)
2362 @end example
2363
2364 @noindent
2365 On a graphical terminal that supports extended @acronym{ASCII} input,
2366 you can still get the standard Emacs meanings of one of those
2367 characters by typing it with the shift key. That makes it a different
2368 character as far as keyboard translation is concerned, but it has the
2369 same usual meaning.
2370
2371 @xref{Translation Keymaps}, for mechanisms that translate event sequences
2372 at the level of @code{read-key-sequence}.
2373
2293 @node Invoking the Input Method 2374 @node Invoking the Input Method
2294 @subsection Invoking the Input Method 2375 @subsection Invoking the Input Method
2295 2376
2296 The event-reading functions invoke the current input method, if any 2377 The event-reading functions invoke the current input method, if any
2297 (@pxref{Input Methods}). If the value of @code{input-method-function} 2378 (@pxref{Input Methods}). If the value of @code{input-method-function}