123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125 |
- <!DOCTYPE html>
- <html lang="en">
- <head>
- <meta charset="UTF-8">
- <meta name="viewport" content="width=device-width, initial-scale=1.0">
- <meta name="description" content="A basic Hello World HTML page with metadata and OpenGraph headers">
- <meta name="author" content="Your Name">
- <title>Hello World</title>
-
- <!-- OpenGraph Metadata -->
- <meta property="og:title" content="Hello World">
- <meta property="og:description" content="A basic Hello World HTML page with metadata and OpenGraph headers">
- <meta property="og:type" content="website">
- <meta property="og:url" content="http://example.com">
- <meta property="og:image" content="http://example.com/image.jpg">
- </head>
- <body>
- <h1>Hello World</h1>
- <p>Welcome to my website!</p>
- <button id="startButton">Start</button>
- <button id="stopButton">Stop</button>
- <button id="capture">Capture</button>
- <script>
- let socket;
- let protocol = window.location.protocol === 'https:' ? 'wss' : 'ws';
- let port = window.location.port ? window.location.port : (protocol === 'wss' ? 443 : 80);
- let socketURL = `${protocol}://${window.location.hostname}:${port}/hid`;
- /* Mouse */
- document.getElementById('capture').addEventListener('click', function() {
- document.body.requestPointerLock();
- document.addEventListener('mousemove', handleMouseMove);
- });
- document.addEventListener('pointerlockchange', function() {
- if (document.pointerLockElement === document.body) {
- console.log('Pointer locked');
- } else {
- console.log('Pointer unlocked');
- document.removeEventListener('mousemove', handleMouseMove);
- }
- });
- function handleMouseMove(event) {
- console.log(`Mouse moved: X=${event.movementX}, Y=${event.movementY}`);
- if (socket) {
- socket.send(JSON.stringify({ t: 'mm', x: event.movementX, y: event.movementY }));
- }
- }
-
- /* Keyboard */
- document.getElementById('startButton').addEventListener('click', function() {
- const socketUrl = socketURL;
- socket = new WebSocket(socketUrl);
- socket.addEventListener('open', function(event) {
- console.log('WebSocket is connected.');
- });
- socket.addEventListener('message', function(event) {
- console.log('Message from server ', event.data);
- });
- document.addEventListener('keydown', handleKeyDown);
- document.addEventListener('keyup', handleKeyUp);
- });
- document.getElementById('stopButton').addEventListener('click', function() {
- if (socket) {
- socket.close();
- console.log('WebSocket is disconnected.');
- }
- document.removeEventListener('keydown', handleKeyDown);
- document.removeEventListener('keyup', handleKeyUp);
- });
- function isNumpadEvent(event) {
- return event.location === 3;
- }
- function handleKeyDown(event) {
- event.preventDefault();
- const key = event.key;
- if (socket){
- if (key == "Shift" || key == "Control" || key == "Alt"){
- if (event.location == 1){
- socket.send(JSON.stringify({ t: 'kw', s: 'kd', d: "LEFT_" + key }));
- } else {
- socket.send(JSON.stringify({ t: 'kw', s: 'kd', d: "RIGHT_" + key }));
- }
- }else if (isNumpadEvent(event)){
- socket.send(JSON.stringify({ t: 'kw', s: 'kd', d: "NUMPAD_" + key }));
- }else if (key == "PrintScreen"){
- //Do nothing, press is hardware offloaded
- }else{
- socket.send(JSON.stringify({ t: 'kw', s: 'kd', d: key }));
- }
- }
- }
- function handleKeyUp(event) {
- event.preventDefault();
- const key = event.key;
- if (socket) {
- if (key == "Shift" || key == "Control" || key == "Alt") {
- if (event.location == 1) {
- socket.send(JSON.stringify({ t: 'kw', s: 'ku', d: "LEFT_" + key }));
- } else {
- socket.send(JSON.stringify({ t: 'kw', s: 'ku', d: "RIGHT_" + key }));
- }
- }else if (isNumpadEvent(event)){
- socket.send(JSON.stringify({ t: 'kw', s: 'ku', d: "NUMPAD_" + key }));
- }else if (key == "NumLock" || key == "Pause"){
- //Do nothing, release is hardware offloaded
- } else {
- socket.send(JSON.stringify({ t: 'kw', s: 'ku', d: key }));
- }
- }
- }
-
- </script>
- </body>
- </html>
|