Squeak
  links to this page:    
View this PageEdit this PageUploads to this PageHistory of this PageTop of the SwikiRecent ChangesSearch the SwikiHelp Guide
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:
  1. obtain the keyboard focus for a HandMorph via the #newKeyboardFocus: method
  2. 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."
ExampleMorph#handlesKeyboard: evt
^ true.
ExampleMorph#keyStroke: anEvent
Transcript show: anEvent keyValue. "Event processing here"
ExampleMorph#keyboardFocusChange: aBoolean
aBoolean
ifTrue: [ Transcript show: 'Got Focus' ]
ifFalse: [ Transcript show: 'Lost Focus']


Key Encodings


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:


keysymdef.h