Add controller functionality to your JavaScript game.
- Supports PlayStation & Xbox
- Really simple API
- ~2.5KB minified
- Vibration support
Add this line to the <body>
:
<script src="https://joycon.js.org/Joycon.min.js"></script>
const controllers = Joycon.controllers;
controllers.on.press('start', (value) => {
console.log('pressed start!', value); // value is 0 to 1
});
Button can be a
, b
, x
, y
, start
, left-trigger
, etc. (full list below)
controllers.on.move('left-joystick', (value) => {
console.log('moved left joystick!', value.x, value.y); // value is -1 to 1 down/right
});
Also right-joystick
.
controllers.on.connect((controller) => {
console.log('controller connected!', controller);
});
controllers.on.disconnect((controller) => {
console.log('controller disconnected!', controller);
});
// preset can be mild, medium or strong
controllers.vibrate({ preset: 'medium' }, 250); // -> time in ms
// or choose your own values
controllers.vibrate({
mildMotorIntensity: 0.5,
strongMotorIntensity: 0.5
}, 250);
controllers.removeListener('left-trigger');
Remove Joystick move
listeners with left-joystick-move
.
Remove controller connect
listeners with controller-connect
.
Buttons: | ||||
---|---|---|---|---|
a |
left-shoulder |
select |
dpad-up |
home |
b |
right-shoulder |
start |
dpad-down |
share |
x |
left-trigger |
left-joystick |
dpad-left |
|
y |
right-trigger |
right-joystick |
dpad-right |
See above on how to use these.
Thanks for coming by!