Here's a little script example for how to use InputContexts from
JavaScript/QtScript. Personally I would recommend using InputContext over
EC_InputMapper as the latter has an uncertain future (there have been talks
that should the component exists or not).
// YourScript.js, included in the scene by creating an entity and adding a
EC_Script component to it,
// and settings the script reference attribute point to the file.
// Register new raw i.e. untracked input context from the Input API
(InputAPI class)
var inputContext = input.RegisterInputContextRaw("MyInputContext", 100);
// After this you can set some input context settings, if wanted, e.g.:
inputContext.SetTakeKeyboardEventsOverQt(true);
// Connect to the event signals
inputContext.KeyEventReceived.connect(OnKeyEvent);
inputContext.MouseEventReceived.connect(OnMouseEvent);
function OnKeyEvent(keyEvent)
{
// Let's use the Console API (class ConsoleAPI) for logging, print() could
be used too.
// You can access the console by pressing F1
console.LogInfo(("Key event for key : " + keyEvent.keyCode + " occurred");
// ... - see the KeyEvent class.
}
function OnMouseEvent(mouseEvent)
{
console.LogInfo(("Mouse event of type " + mouseEvent.eventType + "
occurred.");
// ... - see the MouseEvent class.
}
// "OnScriptDestroyed" is a special signature that is called when the
script is unloaded.
// Good place to perform freeing of resources (untracked InputContext in
this case).
function OnScriptDestroyed()
{
// Unregister raw i.e. untracked input context, so it won't
input.UnregisterInputContextRaw("MyInputContext");
}
--
http://groups.google.com/group/realxtend
http://www.realxtend.org