I am building a chrome extension that would enable the use of my 3d-mouse (made by 3d connexion) to scroll web pages. The built-in 3d connexion drivers are worthless, and the 3d mouse presents itself as a 2 button, 6 axis gamepad to the OS.
The implementation is currently working using the below method:
function get3DMouseData() {
if (document.hasFocus()) {
var gp = navigator.getGamepads()[0]
// axis 5 controls scroll speed
if (gp.axes[5]) window.scrollBy(0,Math.round(gp.axes[5]*10)*10)
}
}
interval = this.setInterval(get3DMouseData, 50)
It doesn't seem to be the smartest strategy to run get3DMouseData
20 times por second, and an event-based implementation would probably be more efficient.
- Is there an event-based methods for the gamepad-api that I can use in the case above?
- This implementation does not work properly in certain sites (like gmail). What I am doing wrong?
There is no such events:
Also it is said that proper polling is a best practice:
Regarding gmail: I guess that it is due restriction policy set on that site:
https://www.w3.org/TR/gamepad/