Morphic Key Events
Last updated at 8:29 am UTC on 24 January 2017
Morphic has three kinds of key events:
To obtain a keyboard event, a morph must do both of the following:
- obtain the keyboard focus for a HandMorph via the #newKeyboardFocus: method
- respond positively to #handlesKeyboard:
Then the event will be sent to either #keyStroke:, #keyUp:, or #keyDown:, as appropriate.
ActiveHand newKeyboardFocus: myExampleMorph "Get Keyboard Focus,e.g. on initialize , mouseOver etc."
Transcript show: anEvent keyValue. "Event processing here"
ifTrue: [ Transcript show: 'Got Focus' ]
ifFalse: [ Transcript show: 'Lost Focus']
Every key event includes an encoding for the key that was pressed or released. For #keyStroke: messages, this key value is the result of interpreting the raw keystroke plus any modifier keys that have been pressed; for example, shift-A yields a capital A.
For #keyUp: and #keyDown:, the key value is reported directly and is not interpreted. Currently, the key values are not platform independent. There is some discussion, as of November 2003, that Squeak might adopt the X11 keystroke definitions. Here's a listing of those definitions: