Next: , Previous: , Up: Api   [Contents][Index]


5.3 Event

One of the idioms we want to capture from Emacs is this.

  (define-key global-map "M-f" 'some-command)

They [[keymap]] and [[command]] module will deal with most of the above, except for the [[kbd]] procedure. That’s something events will be concerned with. One may define a converter for a [[kbd-entry]] to an event of the proper type. Note that a [[kbd-string]] is broken into multiple [[kbd-entries]] on whitespace boundaries, e.g., “C-x C-f” is a [[kbd-string]] that when parsed becomes two [[kbd-entries]] “C-x” and “C-f”.

Class: <event>

Basic event class.

Class: <modifier-key-event>

Event to capture key strokes, including the modifier keys.

Class: <key-event>

Event to capture key strokes, including the modifier keys.

Class: <mouse-event>

Event to capture mouse events.

Class: <drag-mouse-event>

Event to capture mouse drag events.

Class: <dummy-event>
Variable: kbd-converter-functions

Now we have the function [[kbd-entry->key-event]]. [[kbd]] needs to know about this and any other converter function. So let’s register it.

Scheme Procedure: kbd-entry->key-event kbd-entry

Let’s write the converter for the [[<key-event>]] class that will accept the same kind of strings that Emacs does. If the [[kbd-entry]] does not match the event-type, we return false [[#f]].

Scheme Procedure: modifier-char->symbol char

For the modifier keys, we are going to emulate Emacs to a fault.

Scheme Procedure: register-kbd-converter function-name function
Scheme Procedure: kbd->events kbd-string
Scheme Procedure: canonize-event! (event <key-event>)
Scheme Procedure: event->kbd (event <key-event>)

Now we convert the [[<key-event>]] back to a [[kbd-entry]].

Scheme Procedure: event->kbd (event <modifier-key-event>)
Scheme Procedure: modifier-symbol->char sym

Instead of using [[define-generic]] I’ve written a convenience macro [[define-generic-public]] that exports the symbol to the current module. This mimics the functionality of [[define-public]]. In general, any *-public macro will export the symbol or syntax to the

Scheme Procedure: write (obj <key-event>) port

Display the <key-event> in a nice way.

Scheme Procedure: kbd-entry->mouse-event kbd-entry

The kbd-entry for mouse events is similar to key events. The regular expression is ^(([ACHMsS]-)*)((up-|down-|drag-)?mouse-([123]))\$.

Scheme Procedure: up-mouse-event? e
Scheme Procedure: down-mouse-event? e
Scheme Procedure: drag-mouse-event? e
Scheme Procedure: click-mouse-event? e
Scheme Procedure: motion-mouse-event? e

Next: , Previous: , Up: Api   [Contents][Index]