• Advertisement
Sign in to follow this  

Catching Backspace and Esc on Chrome

This topic is 1233 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

OK so, I'm writing something like a DOS simulator in javascript out of boredom. This is what I have so far:

http://sik.titandemo.de/.bludos/

 

The problem I have is with keyboard input. It works just fine on Firefox, but Chrome eats up backspace and esc. I guess that's because they're shortcuts (back and stop loading) but huh, you can see how this can be an issue here (and I'm not even filtering the default actions). Any idea how to get them working?

 

In case you wonder, keyboard input is handled by having a huge inputbox that covers the entire screen and then has opacity 0 (making it transparent), then the script just hooks on its keypress event to retrieve the keyboard input. I haven't tried with keydown yet but as you can imagine ideally I'd want to keep the repeat behavior (especially with backspace). Any suggestions?

 

PS: it may not work on Explorer since I didn't hook up old-style events yet. I suppose modern Explorer does support standard events, but I'm not sure so warning goes here...

 

PS2: yes I know you may argue that catching keys that happen to be shortcuts could be a security hazard, but for that matter being able to detect any keyboard input is a security hazard in the first place =P And I'm not even blocking the default browser actions.

 

EDIT: welp, turns out I had the concept of keydown and keypress wrong along all this time. Keydown is for any key, keypress is for characters only, and both have repeat behavior (I thought only keypress did). Whoops. Well, that fixes it, now character input is handled through keypress and Enter, Backspace and Esc are handled through keydown. That solves the problem.

 

Also if somebody else is having problems with keyboard events, I found this site which is pretty useful (in particular the form at the beginning which lets you test what events trigger):

http://javascript.info/tutorial/keyboard-events

Edited by Sik_the_hedgehog

Share this post


Link to post
Share on other sites
Advertisement
Sign in to follow this  

  • Advertisement