1

Is there a way I can convert a javascript keycode into one that is used by C#?

For example 87 is the character 'w' in javascript, but in C# it's 57. And 77 is 'm' whereas it's 4D in C#. Is there a simple way to convert them? Thanks.

5
  • But shouldn't "w" be 199 = 0x77 = 0167? "W" is 87 = 0x57 = 0127. Commented Jun 6, 2012 at 1:54
  • @D.Shawley: Key codes don't distinguish between upper- and lower-case letters. There's a shiftKey/Shift property for that. Commented Jun 6, 2012 at 1:55
  • Ah, yeah sorry. Was looking at this list delphi.about.com/od/objectpascalide/l/blvkc.htm and it didn't have the lower 'w' so didn't take much notice. Commented Jun 6, 2012 at 1:56
  • @minitech - character codes in JavaScript definitely do not discard case - "w".charCodeAt(0) is 199 and "W".charCodeAt(0) is 87. It sounds like they do in C# though. Learn something new every day. Commented Jun 6, 2012 at 2:00
  • @D.Shawley: I'm talking about the keydown event - key codes, not character codes. C# works the same way; otherwise, there would be some ASCII problems! :) Here's an example jsFiddle. Commented Jun 6, 2012 at 2:00

1 Answer 1

7

The issue isn't that they're different; your C# ones are just in hexadecimal.

8710 = 5716
7710 = 4D16

Just treat them as ints, not as strings, and you'll be fine.

Sign up to request clarification or add additional context in comments.

1 Comment

Thanks! Never knew that. And yeah, it works as ints intead of strings. Thanks again.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.