I have an input box that always has focus. The commands that go into this input box are always letters. If the user presses a number, I would like it not to be added to the text box, but instead use it to run a different command (just like a hotkey).
The way I’ve seen this implemented is by looking at the keyup event and removing unwanted characters. Instead, is there any way to to intercept the keyboard input and check what the value is before the insert?
I’ve thought about creating a custom input field using a div and intercepting all the keyboard commands. Is there a way to get a blinking caret so that it looks like an input box?
Sounds like you want a
contenteditablediv:You can listen for
keydownevents and prevent them if they aren’t letters:To process the numbers as “hotkeys” you would just determine which key
e.whichis and act accordingly.Example: http://jsfiddle.net/g3mgR/1