A convenient event re-director

Questions and information about using Lua scripting with Storyboard

Moderator: jamiev

A convenient event re-director

Postby thomas » Thu Nov 05, 2009 8:22 am

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"])
4:
5: if key_char == 's' then
6: gre.send_event("select")
7: end
8: end

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
event (3).

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.

Thomas
thomas
 
Posts: 70
Joined: Mon Nov 02, 2009 4:32 pm
Location: Ottawa

Return to Lua Scripting

Who is online

Users browsing this forum: No registered users and 0 guests

cron