browser-forward-keyboard-listener
Advanced tools
Comparing version
{ | ||
"name": "browser-forward-keyboard-listener", | ||
"description": "capture mouse and keyboard event from browser and send them back via WS", | ||
"version": "1.0.9", | ||
"version": "1.1.0", | ||
"private": false, | ||
@@ -6,0 +6,0 @@ "main": "dist/index.js", |
@@ -40,4 +40,7 @@ // Create WebSocket connection. | ||
const handleKeyDown = (key:string) => { | ||
// prevent this event to keep firing when the key is held down | ||
if(activeKeys.has(key)) return; | ||
activeKeys.add(key); | ||
socket.send(JSON.stringify({type:'keyDown', key})); | ||
@@ -61,3 +64,3 @@ }; | ||
e.preventDefault(); | ||
handleKeyDown(e.key.toLowerCase()); | ||
handleKeyDown(e.code); | ||
}); | ||
@@ -67,3 +70,3 @@ | ||
e.preventDefault(); | ||
handleKeyUp(e.key.toLowerCase()); | ||
handleKeyUp(e.code); | ||
}); | ||
@@ -73,7 +76,7 @@ | ||
e.preventDefault(); | ||
handleKeyDown("mouse"+e.button); | ||
handleKeyDown("Mouse"+e.button); | ||
}); | ||
document.addEventListener('mouseup', function(e) { | ||
e.preventDefault(); | ||
handleKeyUp("mouse"+e.button); | ||
handleKeyUp("Mouse"+e.button); | ||
}); | ||
@@ -80,0 +83,0 @@ document.addEventListener('contextmenu',(e)=>e.preventDefault()); |
@@ -5,3 +5,5 @@ import {createServer} from "./server"; | ||
export * from "./KeyListenersManager"; | ||
export * from "./keys"; | ||
// open the browser and start listening to user input | ||
export function initKeyboardListener() { | ||
@@ -8,0 +10,0 @@ const port = process.env.PORT || 3000; |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
54717
11.29%41
2.5%586
22.34%