Keyboard Events
Keyboard Events
For keyDown, autoKey, and keyUp events, the layout of theEvent. message is:
Events.h defines the following constants that apply to the message field for
these events:
keyCodeMask (0x0000FF00) mask to extract keyboard scan code
charCodeMask (0x000000FF) mask to extract ASCII character code
abdAddrMask (0x00FF00000) mask to extract adb address code
osEvtMessageMask (0xFF000000) mask to extract OS event message code
The keyboard address field shows which keyboard in a multiple keyboard
configuration is presenting the event.
See Keyboard Layout for information about key codes.
Typical handling of keyDown events includes code such as this:
theChar = theEvent->message & charCodeMask;
theKey = ( theEvent->message & keyCodeMask) >> 8;
if ( theEvent->modifiers & cmdKey) // ... was pressed ... //
In handling both keystrokes and mousedowns, you may wish to test the state
of the modifier keys (, option, control, or shift). Modifier keys are not
reported as keystrokes, but the modifiers field of every EventRecord
( including null events) contains the current status:
Note: keyUp events are normally masked by the Event Manager and never
make it into the event queue. See SetEventMask.
The standard System automatically captures and processes two
Command-Shift-number key combinations. The combinations are:
Command-Shift-1 Eject internal disk
Command-Shift-2 Eject external disk
Combinations for 3 to 9 are also captured by GetNextEvent or
WaitNextEvent but are processed by 'FKEY' resources. You can define
actions for Command-Shift-number combinations for numbers 5 to 9 by
defining your own 'FKEY' resource. The routine should have no parameters and
the ID of the resource has to correspond to the selected 'FKEY'. For example, to
define an action for Command-Shift-8, you would create an 'FKEY' resource
with ID 8.
The following 2 Command-Shift-number key combinations are implemented
with 'FKEY' resources in the standard System file:
Command-Shift-3 Save current screen as a MacPaint file,
with name Screen #
Command-Shift-4 Print the active window to an
ImageWriter
(with Caps Lock enabled) Print the entire screen to an ImageWriter