Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

The big pitfall in the api of browser and keyboard is there is not a method to get the status (keys pressed) of the keyboard.

I know that it is about security stuff, but for the games in js is a bad situation when the canvas lost the focus and the keys pressed change.



I fought with this so much today.

Our robots can be driven remotely via a web app. But there’s ways to accidentally get buttons stuck down because keyup is never guaranteed and you can’t get key state. Two cases: holding down forward key and blur the tab, or open contextmenu.

There’s workarounds of course. But it’s comical spending so much time on something so simplistic.


This might be an appropriate use for the Gamepad API which can be queried on every animation frame for a button’s state.

https://developer.mozilla.org/en-US/docs/Web/API/Gamepad_API...


The Gamepad API is fun, but we’re not trying to implement a gamepad.


How is this a security issue?


You can handle the onblur event and use it to clear all pressed keys.




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: