2.1.24 key-event%

► |  | GUI: Racket Graphics Toolkit

1 | Overview
2 | Reference
3 | Configuration
4 | Dynamic Loading
| Bibliography
| Index

► | 2 | Reference

2.1 | Windowing Classes
2.2 | Windowing Functions
2.3 | Drawing Classes
2.4 | Drawing Functions
2.5 | Editor Classes
2.6 | Editor Functions
2.7 | WXME Decoding

▼ | 2.1 | Windowing Classes

2.1.1 | area<%>
2.1.2 | area-container<%>
2.1.3 | area-container-window<%>
2.1.4 | button%
2.1.5 | canvas<%>
2.1.6 | canvas%
2.1.7 | check-box%
2.1.8 | checkable-menu-item%
2.1.9 | choice%
2.1.10 | clipboard-client%
2.1.11 | clipboard<%>
2.1.12 | combo-field%
2.1.13 | control<%>
2.1.14 | control-event%
2.1.15 | cursor%
2.1.16 | dialog%
2.1.17 | event%
2.1.18 | frame%
2.1.19 | gauge%
2.1.20 | group-box-panel%
2.1.21 | grow-box-spacer-pane%
2.1.22 | horizontal-pane%
2.1.23 | horizontal-panel%
2.1.24 | key-event%
2.1.25 | labelled-menu-item<%>
2.1.26 | list-box%
2.1.27 | list-control<%>
2.1.28 | menu%
2.1.29 | menu-bar%
2.1.30 | menu-item<%>
2.1.31 | menu-item%
2.1.32 | menu-item-container<%>
2.1.33 | message%
2.1.34 | mouse-event%
2.1.35 | pane%
2.1.36 | panel%
2.1.37 | popup-menu%
2.1.38 | radio-box%
2.1.39 | selectable-menu-item<%>
2.1.40 | separator-menu-item%
2.1.41 | scroll-event%
2.1.42 | slider%
2.1.43 | subarea<%>
2.1.44 | subwindow<%>
2.1.45 | tab-panel%
2.1.46 | text-field%
2.1.47 | timer%
2.1.48 | top-level-window<%>
2.1.49 | vertical-pane%
2.1.50 | vertical-panel%
2.1.51 | window<%>

On this page:

get-alt-down
get-caps-down
get-control-down
get-key-code
get-key-release-code
get-meta-down
get-other-altgr-key-code
get-other-caps-key-code
get-other-shift-altgr-key-code
get-other-shift-key-code
get-shift-down
get-x
get-y
set-alt-down
set-caps-down
set-control-down
set-key-code
set-key-release-code
set-meta-down
set-other-altgr-key-code
set-other-caps-key-code
set-other-shift-altgr-key-code
set-other-shift-key-code
set-shift-down
set-x
set-y

Inherited methods:
from event%
get-time-stamp
set-time-stamp

top← prev up next →

key-event% : class?
superclass: event%

A key-event% object contains information about a key press or release event. Key events are primarily processed by on-subwindow-char in window<%> and on-char in canvas<%>.

For a key-press event, a virtual key code is provided by get-key-code. For a key-release event, get-key-code reports 'release, and a virtual key code is provided by get-key-release-code.

See also Mouse and Keyboard Events.

( new key-event% | [ | [key-code key-code] |
|  | [shift-down shift-down] |
|  | [control-down control-down] |
|  | [meta-down meta-down] |
|  | [alt-down alt-down] |
|  | [x x] |
|  | [y y] |
|  | [time-stamp time-stamp] |
|  | [caps-down caps-down]]) |

→ ( is-a?/c key-event%)
key-code : ( or/c char? key-code-symbol?) = #\nul
shift-down : any/c = #f
control-down : any/c = #f
meta-down : any/c = #f
alt-down : any/c = #f
x : exact-integer? = 0
y : exact-integer? = 0
time-stamp : exact-integer? = 0
caps-down : any/c = #f

See the corresponding get- and set- methods for information about key-code, shift-down, control-down, meta-down, alt-down, x, y, time-stamp, caps-down.

The release key code, as returned by get-key-release-code, is initialized to 'press.

( send a-key-event get-alt-down) → boolean?

Returns #t if the Option (Mac OS X) key was down for the event. When the Alt key is pressed in Windows, it is reported as a Meta press (see get-meta-down).

( send a-key-event get-caps-down) → boolean?

Returns #t if the Caps Lock key was on for the event.

( send a-key-event get-control-down) → boolean?

Returns #t if the Control key was down for the event.

Under Mac OS X, if a control-key press is combined with a mouse button click, the event is reported as a right-button click and get-control-down for the event reports #f.

( send a-key-event get-key-code)
→ ( or/c char? key-code-symbol?)

Gets the virtual key code for the key event. The virtual key code is either a character or a special key symbol, one of the following:

- 'start

- 'cancel

- 'clear

- 'shift

- 'control

- 'menu

- 'pause

- 'capital

- 'prior

- 'next

- 'end

- 'home

- 'left

- 'up

- 'right

- 'down

- 'escape

- 'select

- 'print

- 'execute

- 'snapshot

- 'insert

- 'help

- 'numpad0

- 'numpad1

- 'numpad2

- 'numpad3

- 'numpad4

- 'numpad5

- 'numpad6

- 'numpad7

- 'numpad8

- 'numpad9

- 'numpad-enter

- 'multiply

- 'add

- 'separator

- 'subtract

- 'decimal

- 'divide

- 'f1

- 'f2

- 'f3

- 'f4

- 'f5

- 'f6

- 'f7

- 'f8

- 'f9

- 'f10

- 'f11

- 'f12

- 'f13

- 'f14

- 'f15

- 'f16

- 'f17

- 'f18

- 'f19

- 'f20

- 'f21

- 'f22

- 'f23

- 'f24

- 'numlock

- 'scroll

- 'wheel-up – mouse wheel up one notch

- 'wheel-down – mouse wheel down one notch

- 'release – indicates a key-release event

- 'press – indicates a key-press event; usually only from get-key-release-code

The special key symbols attempt to capture useful keys that have no standard ASCII representation. A few keys have standard representations that are not obvious:

- #\space – the space bar

- #\return – the Enter or Return key (on all platforms), but not necessarily the Enter key near the numpad (which is reported as 'numpad-enter if the platform distinguishes the two Enter keys)

- #\tab – the tab key

- #\backspace – the backspace key

- #\rubout – the delete key

If a suitable special key symbol or ASCII representation is not available, #\nul (the NUL character) is reported.

Under X, a 'wheel-up or 'wheel-down event may be sent to a window other than the one with the keyboard focus, because X generates wheel events based on the location of the mouse pointer.

Under Windows, when the Control key is pressed without Alt, the key code for ASCII characters is downcased, roughly cancelling the effect of the Shift key. Under Mac OS X, the key code is computed without Caps Lock effects when the Control or Command key is pressed; in the case of Control, Caps Lock is used normally if special handling is disabled for the Control key via special-control-key. Under X, the key code is computed with Caps Lock effects when the Control key is pressed without Alt.

See also get-other-shift-key-code.

( send a-key-event get-key-release-code)
→ ( or/c char? key-code-symbol?)

Gets the virtual key code for a key-release event; the result is 'press for a key-press event. See get-key-code for the list of virtual key codes.

( send a-key-event get-meta-down) → boolean?

Returns #t if the Meta (X), Alt (Windows), or Command (Mac OS X) key was down for the event.

( send a-key-event get-other-altgr-key-code)
→ ( or/c char? key-code-symbol? false/c)

See get-other-shift-key-code.

( send a-key-event get-other-caps-key-code)
→ ( or/c char? key-code-symbol? false/c)

See get-other-shift-key-code.

( send a-key-event get-other-shift-altgr-key-code)
→ ( or/c char? key-code-symbol? false/c)

See get-other-shift-key-code.

( send a-key-event get-other-shift-key-code)
→ ( or/c char? key-code-symbol? false/c)

Since keyboard mappings vary, it is sometimes useful in key mappings for a program to know the result that the keyboard would have produced for an event if the Shift key had been toggled differently. The get-other-shift-key-code produces that other mapping, returning #f if the alternate mapping is unavailable, otherwise returning the same kind of result as get-key-code.

The get-other-altgr-key-code method provides the same information with respect to the AltGr key (i.e., Alt combined with Control) under Windows and X, or the Option key under Mac OS X. The get-other-shift-altgr-key-code method reports a mapping for in tha case that both Shift and AltGr/Option were different from the actual event.

The get-other-shift-key-code, get-other-altgr-key-code, and get-other-shift-altgr-key-code results all report key mappings where Caps Lock is off, independent of whether Caps Lock was on for the actual event. The get-other-caps-key-code method reports a mapping for in that case that the Caps Lock state was treated opposite as for the get-key-code result. (Caps Lock normally has either no effect or the same effect as Shift, so further combinations involving Caps Lock and other modifier keys would not normally produce further alternatives.)

Alternate mappings are not available for all events. Under Windows, alternate mappings are reported when they produce ASCII letters, ASCII digits, and ASCII symbols. Under Mac OS X, alternate mappings are available only when the Command key is pressed. Under X, alternate mappings are usually available.

( send a-key-event get-shift-down) → boolean?

Returns #t if the Shift key was down for the event.

( send a-key-event get-x) → exact-integer?

Returns the x-position of the mouse at the time of the event, in the target’s window’s (client-area) coordinate system.

( send a-key-event get-y) → exact-integer?

Returns the y-position of the mouse at the time of the event in the target’s window’s (client-area) coordinate system.

( send a-key-event set-alt-down down?) → void?
down? : any/c

Sets whether the Option (Mac OS X) key was down for the event. When the Alt key is pressed in Windows, it is reported as a Meta press (see set-meta-down).

( send a-key-event set-caps-down down?) → void?
down? : any/c

Sets whether the Caps Lock key was on for the event.

( send a-key-event set-control-down down?) → void?
down? : any/c

Sets whether the Control key was down for the event.

Under Mac OS X, if a control-key press is combined with a mouse button click, the event is reported as a right-button click and get-control-down for the event reports #f.

( send a-key-event set-key-code code) → void?
code : ( or/c char? key-code-symbol?)

Sets the virtual key code for the event, either a character or one of the special symbols listed with get-key-code.

( send a-key-event set-key-release-code code) → void?
code : ( or/c char? key-code-symbol?)

Sets the virtual key code for a release event, either a character or one of the special symbols listed with get-key-code. See also get-key-release-code.

( send a-key-event set-meta-down down?) → void?
down? : any/c

Sets whether the Meta (X), Alt (Windows), or Command (Mac OS X) key was down for the event.

( send a-key-event set-other-altgr-key-code code) → void?
code : ( or/c char? key-code-symbol? false/c)

Sets the key code produced by get-other-altgr-key-code.

( send a-key-event set-other-caps-key-code code) → void?
code : ( or/c char? key-code-symbol? false/c)

Sets the key code produced by get-other-caps-key-code.

( send a-key-event set-other-shift-altgr-key-code code) → void?
code : ( or/c char? key-code-symbol? false/c)

Sets the key code produced by get-other-shift-altgr-key-code.

( send a-key-event set-other-shift-key-code code) → void?
code : ( or/c char? key-code-symbol? false/c)

Sets the key code produced by get-other-shift-key-code.

( send a-key-event set-shift-down down?) → void?
down? : any/c

Sets whether the Shift key was down for the event.

( send a-key-event set-x pos) → void?
pos : exact-integer?

Sets the x-position of the mouse at the time of the event in the target’s window’s (client-area) coordinate system.

( send a-key-event set-y pos) → void?
pos : exact-integer?

Sets the y-position of the mouse at the time of the event in the target’s window’s (client-area) coordinate system.
top← prev up next →