Keyboard in CoSpaces

99 views
Skip to first unread message

chabala...@hfa-pgh.org

unread,
Oct 2, 2017, 11:21:39 AM10/2/17
to CoSpaces
Is there a way to interact with the keyboard in CoSpaces?

For example, when I click the space bar, a certain thing would happen?

I would like to possibly combine it with a game controller created with a MakeyMakey or something like that, which is why I would like to know.

Michael Fricano II

unread,
Oct 3, 2017, 1:20:58 PM10/3/17
to CoSpaces
Love the idea! Following.

Benjamin Singh

unread,
Oct 4, 2017, 4:56:37 AM10/4/17
to CoSpaces
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.

Here is a working example: https://cospac.es/z078

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
Reply all
Reply to author
Forward
0 new messages