开发者

Keyboard Number Line vs Keypad Numbers

I'm using Javascript, I need to get the keypad numbers. For what ever reason, my code treats them differently.

function getKey(keyStroke) {
    var keyCode = (document.layers) ? keyStroke.which : event.keyCode;
    var keyString = String.fromCharCode(keyCode).toLowerCase();
        if (lop.charAt(cpos)==keyString) {
        document.getElementById("pimachine_e").innerHTML=document.getElementById("pimachine_e").innerHTML+keyString;
                cpos++;
        } else {
        lose();
        }
}

The number line at the top of the keyboard acts like 开发者_运维技巧expected but the Numberpad is treated (when I click 1) as if I haven't clicked 1. What is it changing it to? How do I get these key presses correctly.


http://www.cambiaresearch.com/c4/702b8cd1-e5b0-42e6-83ac-25f0306e3e25/Javascript-Char-Codes-Key-Codes.aspx

That shows a list with all of the keys on a regular keyboard and the keycodes that are associated with it. As you can see, when pressing 'numpad 1', it should return '97' in this line:

var keyCode = (document.layers) ? keyStroke.which : event.keyCode;

Maybe you can put an alert after that line to check if the variable 'keyCode' has ben filled correctly?

If that doesn't help you along your way, please provide more code, cause I cannot recreate your situation locally because your function is referring to other pieces of code that are not provided. Also, I can't see how this function is being called and how the variable 'keyStroke' is filled.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜