0

I am making a simple program that binds each key to a character.
I noticed that the keycode of ' key is the same as right arrow key. both are 39.

How can I distinguish between these 2 (and other conflicts). Please dont tell me to use key combination with the right arrow. I dont want to do that.
This is the alerter which alerts the code (Ive tested with it , both give 39):

<html><head>
<meta http-equiv="content-type" content="text/html; charset=UTF-8">
<script type="text/javascript">
function code(e) {
    e = e || window.event;
    return(e.keyCode || e.which);
}
window.onload = function(){
    document.onkeypress = function(e){
        var key = code(e);
        alert(key);
    };
};
</script>
</head>
<body>
</body>
</html>
Markus
  • 3,225
  • 6
  • 35
  • 47
TechLife
  • 143
  • 8
  • 2
    ```right arrow``` is 39, ```'``` is 222. They cannot be the same. Can you show the code that is producing this error? – Thalsan Apr 29 '15 at 14:47
  • Items that dupe are often invoked via a shift key + the key to get there. I would suggest having a look at: https://github.com/RobertWHurst/KeyboardJS But, also, I would re-consider your approach to trapping keys like this, especially in the day and age of mobile keyboards, voice command form fill ins, etc. – BReal14 Apr 29 '15 at 14:49
  • @Thalsan in the edit -> – TechLife Apr 29 '15 at 14:52
  • 1
    Use keyup and keydown for capturing keycodes http://stackoverflow.com/questions/11030532/keypress-and-keyup-why-is-the-keycode-different – garryp Apr 29 '15 at 21:31

0 Answers0