1

This bit of code generates that error in Chrome's JavaScript console & I'm not sure why. After Googling around for people with similar issues, I haven't found any D:

The error message suggests that the issue is with the event.which() but I don't see how I'm using it any differently from expected, other people with similar don't seem to have had problem with it.

$(document).keypress(function(event) {
    switch (event.which()) {            
        case 38 :   keyNorthPressed = true;
                    break;
        case 39 :   keyEastPressed = true;
                    break;
        case 40 :   keySouthPressed = true;
                    break;
        case 41 :   keyWestPressed = true;
                    break;
    }
});

Thanks in advance.


You may also need to assume the following:

  • There is only one type of lamp in the room. E.g. the wall and the coke may be lit by two different light sources.
  • The spectral distribution of the lamp. It is easy to model incandescents, but LED and CFL may vary with which brand is used.
  • The spectral response of the camera. Some cameras do not register light in the low and high wavelengths.

Basically, you need to read about metamerism.

You may find yourself in a situation where if you were to take a picture of the two walls, they have the same color. But if you look at them in person, they have distinct colors.

4

1 に答える 1

1

ここに答えがあります。

イベント キー コードを取得する方法は 2 つあります。

event.keyCode or event.which

コードは次のようになります。

$(document).keypress(function(event) {
    var code = event.keyCode || event.which;
    switch(code) {       
        case 38 :   keyNorthPressed = true;
                    break;
        case 39 :   keyEastPressed = true;
                    break;
        case 40 :   keySouthPressed = true;
                    break;
        case 41 :   keyWestPressed = true;
                    break;
    }
});

event.keyCode と event. はメソッドではなく属性であるため、() で呼び出すことはできません。

于 2013-02-23T13:22:12.773 に答える