Skip to content

Commit

Permalink
Adding the gamepad testing stuff
Browse files Browse the repository at this point in the history
  • Loading branch information
Marko Novakovic committed Mar 31, 2024
1 parent ad3b657 commit ac6e223
Showing 1 changed file with 40 additions and 0 deletions.
40 changes: 40 additions & 0 deletions docs/gamepadtest.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Gamepad API Example</title>
<style>
body {
background-color: white;
text-align: center;
font-family: Arial, sans-serif;
padding-top: 100px;
}
</style>
</head>
<body>
<h1>Press a button on your gamepad</h1>
<script>
let gamepadConnected = false;
function handleGamepad() {
const gamepads = navigator.getGamepads();
if (!gamepads[0]) return;
const buttonPressed = gamepads[0].buttons.some(button => button.pressed);
if (buttonPressed) {
document.body.style.backgroundColor = "black";
} else {
document.body.style.backgroundColor = "white";
}
requestAnimationFrame(handleGamepad);
}
window.addEventListener("gamepadconnected", (event) => {
gamepadConnected = true;
handleGamepad();
});
window.addEventListener("gamepaddisconnected", (event) => {
gamepadConnected = false;
document.body.style.backgroundColor = "white";
});
</script>
</body>
</html>

0 comments on commit ac6e223

Please sign in to comment.