Skip to content

Instantly share code, notes, and snippets.

@ruzli
Created February 5, 2024 22:04
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ruzli/5dc12deb99dbf4c8c5dd8a2e96818154 to your computer and use it in GitHub Desktop.
Save ruzli/5dc12deb99dbf4c8c5dd8a2e96818154 to your computer and use it in GitHub Desktop.
wss.js
const wss = new WebSocket('ws://localhost:4041');
wss.addEventListener('open', () => {
console.log(getCurrentTime() + 'Connected');
});
wss.addEventListener('close', () => {
console.log(getCurrentTime() + 'Disconnected');
});
function getCurrentTime() {
return "[" + String(new Date().toLocaleTimeString('en-US', { timeZone: 'Europe/Moscow' })) + "] ";
}
console.log('Started ' + getCurrentTime());
document.addEventListener('keydown', (event) => {
const key = event.key;
wss.send(JSON.stringify({ hotkey: key }));
console.log(getCurrentTime() + `"${key.toUpperCase()}" was pressed.`);
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment