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

I've been struggling with this for a little bit. I have a web application that I'm developing that needs to support keyboard shortcuts. It's basically a giant SVG element on the page with a toolbar at the top, and some popup windows. The problem seems to be always capturing the keys. As long as the user interacts with the SVG element, everything is fine. However, if they move their mouse over the navigation bar (for instance) absentmindedly, then press "Delete", there seems to be a good chance they will end up "going back" instead of me having a chance to see that keypress and intercept it.

Is there any reliable way that works in modern browsers (Firefox, Chrome, Safari) of capturing all the key events on a page, outside of using something like jquery.hotkeys and just doing:

$(document).bind("keyup", "delete", function() { });

Is $(window) better? Some other element I'm not thinking of?



I posted this as a question on SO as well: http://stackoverflow.com/questions/4959487/best-way-to-captu...

Just in case someone comes across this later on Google.




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

Search: