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

Just a general advice for writing HTML games: remember to preventDefault() on all keyboard-related events (keydown, keypress) for all keys you use when your game has focus (add tabindex to your canvas so you'll get focus/blur events).

Otherwise browser's shortcuts could interfere with your game. I have Opera customized with 1-key shortcuts (with no modifier key) and that's a minefield in games that assume keyboard is all for them.



hmm preventDefault() was not built into the older Operas.

apparently the guys fixed preventDefault() on Opera 11.10, as explained here: http://impactjs.com/forums/help/binding-keys-in-opera-not-wo...


preventDefault() worked in Opera since ancient times. However, Opera took default action on different event than other browsers (keydown instead of keypress if I remember correctly).


Yeah, bummer. Hit X and the tab closed. Fun game though, kudos.




Consider applying for YC's Summer 2026 batch! Applications are open till May 4

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

Search: