press X button with gamepad

This commit is contained in:
Thijs Wenker 2014-12-31 02:25:55 +01:00
parent 398e88107c
commit c73b496cac
3 changed files with 33 additions and 0 deletions

View file

@ -121,6 +121,21 @@ function scriptEnding() {
Controller.releaseKeyEvents({key: ENTER_CHARCODE});
}
function reportButtonValue(button, newValue, oldValue) {
if (button == Joysticks.BUTTON_FACE_LEFT) {
if (newValue) {
keyboard.pressFocussedKey();
} else {
keyboard.releaseKeys();
}
}
}
function addJoystick(gamepad) {
gamepad.buttonStateChanged.connect(reportButtonValue);
}
Joysticks.joystickAdded.connect(addJoystick);
Controller.captureKeyEvents({key: RETURN_CHARCODE});
Controller.captureKeyEvents({key: ENTER_CHARCODE});
Controller.captureKeyEvents({key: SPACEBAR_CHARCODE});

View file

@ -179,6 +179,9 @@ KeyboardKey = (function(keyboard, keyProperties) {
});
Keyboard = (function(params) {
if (params === undefined) {
params = {};
}
var tthis = this;
this.focussed_key = -1;
this.scale = (windowDimensions.x / KEYBOARD_WIDTH) * KEYBOARD_SCALE_MULTIPLIER;

View file

@ -152,6 +152,21 @@ function scriptEnding() {
Controller.releaseKeyEvents({key: SPACEBAR_CHARCODE});
}
function reportButtonValue(button, newValue, oldValue) {
if (button == Joysticks.BUTTON_FACE_LEFT) {
if (newValue) {
keyboard.pressFocussedKey();
} else {
keyboard.releaseKeys();
}
}
}
function addJoystick(gamepad) {
gamepad.buttonStateChanged.connect(reportButtonValue);
}
Joysticks.joystickAdded.connect(addJoystick);
Controller.captureKeyEvents({key: SPACEBAR_CHARCODE});
Controller.keyPressEvent.connect(keyPressEvent);
Controller.keyReleaseEvent.connect(keyReleaseEvent);