Hi,
we have a couple internal methods to handle keyboard events in CoSpaces. But they're not public and not documented. Means that they can change anytime and scripts can break. Please keep this in mind when you're using them.
The events are handled as follows:
Scene.onButtonDown(function() {
// Do something once when "w" key is pressed
}, 'w');
Scene.onButtonUp(function() {
// Do something once when "w" key is released
}, 'w');
Scene.onButtonPressed(function() {
// Do something as long as "w" key is pressed
}, 'w');
The first argument is a callback function which is being executed when the key you specify as the second argument is pressed.
Code used in example:
var balloons = Scene.createItem('LP_Balloons', 0, 0, 0);
var dz = 0.05;
Scene.onButtonPressed(function() {
var z = balloons.getPosition().z;
balloons.setPosition(0, 0, z + dz);
}, 'space');
Let us know if you have any questions.
Thanks,
Benjamin