Go to the first, previous, next, last section, table of contents.


Reading One Event

The lowest level functions for command input are those that read a single event.

Function: read-event
This function reads and returns the next event of command input, waiting if necessary until an event is available. Events can come directly from the user or from a keyboard macro.

The function read-event does not display any message to indicate it is waiting for input; use message first, if you wish to display one. If you have not displayed a message, read-event prompts by echoing: it displays descriptions of the events that led to or were read by the current command. See section The Echo Area.

If cursor-in-echo-area is non-nil, then read-event moves the cursor temporarily to the echo area, to the end of any message displayed there. Otherwise read-event does not move the cursor.

Here is what happens if you call read-event and then press the right-arrow function key:

(read-event)
     => right

Function: read-char
This function reads and returns a character of command input. It discards any events that are not characters, until it gets a character.

In the first example, the user types the character 1 (ASCII code 49). The second example shows a keyboard macro definition that calls read-char from the minibuffer using eval-expression. read-char reads the keyboard macro's very next character, which is 1. Then eval-expression displays its return value in the echo area.

(read-char)
     => 49

;; We assume here you use M-: to evaluate this.
(symbol-function 'foo)
     => "^[:(read-char)^M1"
(execute-kbd-macro 'foo)
     -| 49
     => nil


Go to the first, previous, next, last section, table of contents.