How can I handle ArrowKeys and < (Greater Than) in a Javascript function? Which event and which code (charCode Or keyCode)?
I am very confused how to do this. I have read this link very carefully,
Events and keyCode+charCode, but I could not find any solution for my scenario.
Using
event.keyCodeis sufficient. You only need to browser compatibility issues with regard to obtaining the key event into account.Here’s a basic kickoff example which captures arrow keys, copy’n’paste’n’run it:
Note that attaching events is better to be done this way or using jQuery.
For capturing the pressed characters like
<, have a look at Tim’s answer.