Detecting the keyboard

An actor is in fact a combination of an event name and a function that takes some arguments, principally the widget on which the event occurs and the event itself. The following code snippet shows how to detect when certain keys are pressed:

;-- see Chapter09/key-detecting.red:view/options [         t: text "hit 'space', 'a', or '?' keys !"][    actors: object [on-key: func [key event] [            if event/key = #"a" [t/text: "'a' key pressed."]            if event/key = #"?" [t/text: "'?' key pressed."]            if event/key = #" " [t/text: "'space bar'pressed."]         ]    ]]

Get Learn Red - Fundamentals of Red now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.