kallaspriit / html5-javascript-gamepad-controller-library Goto Github PK
View Code? Open in Web Editor NEWLibrary for accessing gamepads in modern browsers.
Home Page: http://kallaspriit.github.com/HTML5-JavaScript-Gamepad-Controller-Library/
Library for accessing gamepads in modern browsers.
Home Page: http://kallaspriit.github.com/HTML5-JavaScript-Gamepad-Controller-Library/
The naming guidelines for events got enforced and they will be all without prefix and lowercase (in the next Aurora build that supports Gamepad API again):
https://bugzilla.mozilla.org/show_bug.cgi?id=604039#c206
The attached test page to this bug also uses these new names.
It's kind of hard to read (count) the indices in the array
s to figure out which buttons/axes are mapped to which indices. It would be nice if we could specify the buttons and axes mappings as an object
with each key being the constant string (e.g., 'LEFT_TOP_SHOULDER'
) instead of the index (e.g., 4
).
Buttons:
https://github.com/kallaspriit/HTML5-JavaScript-Gamepad-Controller-Library/blob/af601ac2/gamepad.js#L481
https://github.com/kallaspriit/HTML5-JavaScript-Gamepad-Controller-Library/blob/af601ac2/gamepad.js#L424-L430
Axes:
https://github.com/kallaspriit/HTML5-JavaScript-Gamepad-Controller-Library/blob/af601ac2/gamepad.js#L484
https://github.com/kallaspriit/HTML5-JavaScript-Gamepad-Controller-Library/blob/af601ac2/gamepad.js#L438
I was confused about FACE_1
, FACE_2
, FACE_3
, and FACE_4
until I read http://www.html5rocks.com/en/tutorials/doodles/gamepad/ and used http://www.html5rocks.com/en/tutorials/doodles/gamepad/gamepad-tester/tester.html
I'm still unsure of SELECT_BACK
and START_FORWARD
. The aforementioned tutorial refers to SELECT
and START
only; what would back and forward do on particular controllers?
And what should HOME
do (I thought this would be similar to Select, but I'm probably just unfamiliar with controllers that have Home buttons).
Hi all, for several weeks the chrome console has been returning the following message: "gamepad.js: 34 getGamepad will now require Secure Context. Please update your application accordingly. For more information see w3c/gamepad#120 "
Does anyone know how to fix. Thanks
Heya!
The problem is that when you press any button, the gamepad is disconnected and reconnected
This happens on Button up event, for some reason "gamepads.indexOf(gamepad)" return -1 and disconnect gamepads.
When "this.knownGamepads[i]" has the gamepads Array
it's very strange, I don't understand why this is happening
Code example in the repository also does not work, the problem is in the library
Please help solve this problem
In March 2014 Chromium unprefixed the navigator.webkitGetGamepads
API as navigator.getGamepads
(which is the standard, and Firefox already supports this too).
The code in WebKitPlatform.factory
should check for the unprefixed version as well.
As a user of the library, I don't want to be concerned what kind of gamepad is connected; I don't care whether the button is called "A" or "SQUARE" for instance.
While the spec does not specify the names, the HTML5Rocks page has a nice image showcasing example names.
Any device specific names could then be layered over them should a UI need them. But the technical names should be unified.
Maybe if a special option is passed, the Gamepad
could synthesise gamepadconnected
and gamepaddisconnected
events. Using a requestAnimationFrame
loop, we would just check the state of navigator.getGamepads()
.
Not sure if this is a good idea, but it would fix #21 and could be useful for devs since I'm sure many devs have to do this themselves anyway.
I've got an older Logitech gamepad, which is reported as
"Gamepad #0: 046d-c216-Logitech Logitech Dual Action (logitech)"
and looks like this one: http://www.geeks.com/details.asp?invtid=963292-0403
Notable difference to current ones: ABXY buttons are labelled 2314 (and no vibration function)
The button layout for this one is identical to WEBKIT_LOGITECH and is thus mixed up in the current FIREFOX_LOGITECH.
Yet there are several factors playing together:
What to do?
The Library fails to detect the XBOX 360 Gamepad as an XBOX gamepad and supports it as an unknown controller.
Here's the ID Info. Dumped through Chrome 26.0.1410.63.
Unsupported controller connected
Gamepad {buttons: Array[17], axes: Array[4], timestamp: 1351764, index: 0, id: "©Microsoft Corporation Controller (STANDARD GAMEPAD Vendor: 045e Product: 028e)"…}
axes: Array[4]
0: 0.08609271794557571
1: -0.056611835956573486
2: 0.013000885024666786
3: 0.08087404817342758
length: 4
proto: Array[0]
buttons: Array[17]
0: 0
1: 0
2: 0
3: 0
4: 0
5: 0
6: 0
7: 0
8: 0
9: 0
10: 0
11: 0
12: 0
13: 0
14: 0
15: 0
16: 0
length: 17
proto: Array[0]
id: "©Microsoft Corporation Controller (STANDARD GAMEPAD Vendor: 045e Product: 028e)"
index: 0
timestamp: 1351764
type: "unsupported"
proto: Gamepad
This is using an official gamepad connected via USB.
I have a few ideas to enhance the library, and instead of rolling my own (and yet another), I'd like to contribute here.
But before I do that, I'd like to ask for some guidelines, specifically .jshintrc and .jsbeautifyrc files.
Furthermore I'd like to have the build scripts as part of the repository as well; I don't know what you are using, but I'd be happy to add a grunt based setup.
I could be missing something, but the demo doesn't work in Chrome stable (Version 35.0.1916.153) nor Chrome Canary (Version 38.0.2093.3 canary [64-bit]).
Since Chrome doesn't fire gamepadconnected
or gamepaddisconnected
events like Firefox does, it doesn't look like we initialise a gamepad.
At least for demo purposes, could we poll using requestAnimationFrame
to detect when a game pad is connected, and then initialise the demo?
the BUTTON_DOWN one works but the BUTTON_UP one does nothing
Software used:
Chrome
Hardware used:
PS3 controller and charging cable
When PS3 controller is connected to the computer via both wire and bluetooth, browser will connect the same controller up twice but only report events for the newest gamepad connection.
This is a problem when playing a one player game as the code for the game wont ever reference a second gamepad and the only way to resolve this is to disconnect one of the connections and then restart the browser.
how can I make mappings ? is there any guide or tutorial ?? an example maybe ?!
Hi,
Awesome project! Saves me a lot of time.
I've got it working on windows, but the mapping in chrome / linux with my xbox 360 controller is wrong.
I've been looking at the code for a way to override the mapping for linux, but am I right in saying that currently there is no filter for platform? mac / windows / linux?
Many thanks,
Thijs
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.