Many times you want to drive your interface using different inputs. For example you might have a remote control for the product, but during development it is easier to use the keyboard or mouse.
By using custom named events as the trigger for our actions, we can easily accomplish this redirection with a generic Lua script function.
Add the following Lua function callback as an action associated with the gre.keydown event and you've got a simple re-director:
1: function cb_key_press(mapargs)
2: local ev = mapargs["context_event_data"];
3: local key_char = string.format("%c", ev["code"])
5: if key_char == 's' then
Here we extract out the triggering event data associated with the action (2) and we'll assume that
we've bound this callback to the gre.keypress event so we can get the "code" associated with that
Then it is a simple matter of mapping the key to the event we want to generate (5) and sending
the new event (6) using the Storyboard Lua extensions. In this case we send a new event, named
"select" back to the application.