API for seesaw.keymap
-
by Dave Ray
Full namespace name:
seesaw.keymap
Overview
Functions for mapping key strokes to actions.
Public Variables and Functions
map-key
function
Usage: (map-key target key act & {:keys [scope id], :as opts})
Install a key mapping on a widget.
Key mappings are hopelessly entwined with keyboard focus and the widget
hierarchy. When a key is pressed in a widget with focus, each widget up
the hierarchy gets a chance to handle it. There three 'scopes' with
which a mapping may be registered:
:self
The mapping only handles key presses when the widget itself has
the keyboard focus. Use this, for example, to install custom
key mappings in a text box.
:descendants
The mapping handles key presses when the widget itself or any
of its descendants has keyboard focus.
:global
The mapping handles key presses as long as the top-level window
containing the widget is active. This is what's used for menu
shortcuts and should be used for other app-wide mappings.
Given this, each mapping is installed on a particular widget along
with the desired keystroke and action to perform. The keystroke can
be any valid argument to (seesaw.keystroke/keystroke). The action
can be one of the following:
* A javax.swing.Action. See (seesaw.core/action)
* A single-argument function. An action will automatically be
created around it.
* A button, menu, menuitem, or other button-y thing. An action
that programmatically clicks the button will be created.
* nil to disable or remove a mapping
target may be a widget, frame, or something convertible through to-widget.
Returns a function that removes the key mapping.
Examples:
; In frame f, key "K" clicks button b
(map-key f "K" b)
; In text box t, map ctrl+enter to a function
(map-key t "control ENTER"
(fn [e] (alert e "You pressed ctrl+enter!")))
See:
(seesaw.keystroke/keystroke)
http://download.oracle.com/javase/tutorial/uiswing/misc/keybinding.html