Keydown strange keyCodes


#1

I’m writing a package that needs a single character of input - enter a character and it extends the current selection/selections to the next instance of the given character. It is designed to be a quick editing command and I don’t want the user to have to press Enter, etc.

So far I’ve cobbled something together by studying Find and Replace and trial and error. I have a mini-editor and capture keydown and everything works for normal letters. When I press comma, however, I get keyCode 188, not 44 like I would expect. This is the Unicode 1/4 character and not a comma.

So I guess the best way to ask this is in this order:

  1. Is there a better way to get a single character input?
  2. Is there a better event than keydown? content-modified has a long delay for this kind of command
  3. If I do need to use keyDown, any way to get the correct keys?

Thanks.


#2

Looks like these are JavaScript key codes, not ASCII/Unicode …

http://www.javascripter.net/faq/keycodes.htm


#3

Thanks. That link straightened me out.

I knew to use fromCharCode, but I was using the keydown e.keyCode, not the keypress’s charCode. Somehow, even after all these years of Javascript, I forgot that keydown and keypress generated different codes and I forgot keyCode and charCode were different. A bit embarrassing. Thanks again.