48 lines
1.6 KiB
HTML
48 lines
1.6 KiB
HTML
<!DOCTYPE html>
|
|
<html>
|
|
|
|
<head>
|
|
<title>GamePad手柄示例</title>
|
|
<meta http-equiv="Content-type" content="text/html; charset=utf-8">
|
|
<meta name="viewport" content="width=device-width, initial-scale=1, minimum-scale=1">
|
|
<meta http-equiv="X-UA-Compatible" content="IE=Edge,chrome=1">
|
|
<link href="/jscss/style.css" rel="stylesheet" type="text/css" />
|
|
<style>
|
|
</style>
|
|
</head>
|
|
|
|
<body class="px4 py4">
|
|
<blockquote>getGamepads 0-3</blockquote>
|
|
<div class="flex">
|
|
<pre id="gamepad0"></pre>
|
|
<pre id="gamepad1"></pre>
|
|
<pre id="gamepad2"></pre>
|
|
<pre id="gamepad3"></pre>
|
|
</div>
|
|
<script type="text/javascript" src="/jscss/ciy.js"></script>
|
|
<script>
|
|
var Glob = {};
|
|
function checkGamepadsHandel() {
|
|
let gamepads = navigator.getGamepads();
|
|
for (let i = 0; i < gamepads.length; i++) {
|
|
let gamepad = gamepads[i];
|
|
if (!gamepad)
|
|
continue;
|
|
var pre = JSON.stringify(gamepad.axes, null, 2) + '\n';
|
|
for (var bi in gamepad.buttons) {
|
|
pre += bi + ':' + gamepad.buttons[bi].pressed + ',' + gamepad.buttons[bi].touched + ',' + gamepad.buttons[bi].value + '\n';
|
|
}
|
|
$5('#gamepad' + i).text(pre);
|
|
}
|
|
}
|
|
Glob._gametimer = null;
|
|
addEventListener("gamepadconnected", (event) => {
|
|
Glob._gametimer = setInterval(checkGamepadsHandel, 50);
|
|
});
|
|
addEventListener("gamepaddisconnected", (event) => {
|
|
clearInterval(Glob._gametimer);
|
|
});
|
|
</script>
|
|
</body>
|
|
|
|
</html> |