javascript keyCode

阅读更多
var keyEvent = {
        'VK_LEFT': 37,
        'VK_RIGHT': 39,
        'VK_UP': 38,
        'VK_DOWN': 40,
        'VK_INSERT': 45,
        'VK_DELETE': 46,
        'VK_BACK_SPACE': 8,
        'VK_TAB': 9,
        'VK_ENTER': 13,
        'VK_SHIFT': 16,
        'VK_CTRL': 17,
        'VK_ALT': 18,
        'VK_PAUSE': 19,
        'VK_ESC': 27,
        'VK_SPACE': 32,
        'VK_PAGE_UP': 33,
        'VK_PAGE_DOWN': 34,
        'VK_END': 35,
        'VK_HOME': 36,
        'VK_F1': 112,
        'VK_F2': 113,
        'VK_F3': 114,
        'VK_F4': 115,
        'VK_F5': 116,
        'VK_F6': 117,
        'VK_F7': 118,
        'VK_F8': 119,
        'VK_F9': 120,
        'VK_F10': 121,
        'VK_F11': 122,
        'VK_F12': 123,
        'VK_A': 65,
        'VK_B': 66,
        'VK_C': 67,
        'VK_D': 68,
        'VK_E': 69,
        'VK_F': 70,
        'VK_G': 71,
        'VK_H': 72,
        'VK_I': 73,
        'VK_J': 74,
        'VK_K': 75,
        'VK_L': 76,
        'VK_M': 77,
        'VK_N': 78,
        'VK_O': 79,
        'VK_P': 80,
        'VK_Q': 81,
        'VK_R': 82,
        'VK_S': 83,
        'VK_T': 84,
        'VK_U': 85,
        'VK_V': 86,
        'VK_W': 87,
        'VK_X': 88,
        'VK_Y': 89,
        'VK_Z': 90,
        'VK_ZERO': 48,
        'VK_ONE': 49,
        'VK_TWO': 50,
        'VK_THREE': 51,
        'VK_FOUR': 52,
        'VK_FIVE': 53,
        'VK_SIX': 54,
        'VK_SEVEN': 55,
        'VK_EIGHT': 56,
        'VK_NINE': 57
};

var keyEvent = {'VK_LEFT': 37,'VK_RIGHT': 39,'VK_UP': 38,'VK_DOWN': 40,'VK_INSERT': 45,'VK_DELETE': 46,
'VK_BACK_SPACE': 8,'VK_TAB': 9,'VK_ENTER': 13,'VK_SHIFT': 16,'VK_CTRL': 17,'VK_ALT': 18,'VK_PAUSE': 19,
'VK_ESC': 27,'VK_SPACE': 32,'VK_PAGE_UP': 33,'VK_PAGE_DOWN': 34,'VK_END': 35,'VK_HOME': 36,'VK_F1': 112,
'VK_F2': 113,'VK_F3': 114,'VK_F4': 115,'VK_F5': 116,'VK_F6': 117,'VK_F7': 118,'VK_F8': 119,'VK_F9': 120,
'VK_F10': 121,'VK_F11': 122,'VK_F12': 123,'VK_A': 65,'VK_B': 66,'VK_C': 67,'VK_D': 68,'VK_E': 69,
'VK_F': 70,'VK_G': 71,'VK_H': 72,'VK_I': 73,'VK_J': 74,'VK_K': 75,'VK_L': 76,'VK_M': 77,'VK_N': 78,
'VK_O': 79,'VK_P': 80,'VK_Q': 81,'VK_R': 82,'VK_S': 83,'VK_T': 84,'VK_U': 85,'VK_V': 86,'VK_W': 87,
'VK_X': 88,'VK_Y': 89,'VK_Z': 90,'VK_ZERO': 48,'VK_ONE': 49,'VK_TWO': 50,'VK_THREE': 51,'VK_FOUR': 52,
'VK_FIVE': 53,'VK_SIX': 54,'VK_SEVEN': 55,'VK_EIGHT': 56,'VK_NINE': 57
};


//判断哪个鼠标键被按下
var divObj = $('d');
divObj.onmousedown = rightButtonPressed;
function rightButtonPressed(e) {
    var ev = e || window.event;
    if (ev.button && ev.button == 2) {
        alert('right');
        //处理右键
        return false;
    } else {
        alert('other');
    }
    return false;
}

//onkeydown事件:只要按键不抬起来就会持续触发 keydown 事件
document.onkeydown = handleArrowKeys;
function handleArrowKeys(e) {
    var ev = e || window.event;
    var top = divObj.style.top;
    var left = divObj.style.left;
    //var keyCode = (ev.charCode) ? ev.charCode : ev.keyCode;
    switch(ev.keyCode) {
        case 37: case 65: //left arrow
            divObj.style.left = (parseInt(left) - 5) + 'px';
            break;
        case 38: case 87: //top arrow
            divObj.style.top = (parseInt(top) - 5) + 'px';
            break;
        case 39: case 68: //right arrow
            divObj.style.left = (parseInt(left) + 5) + 'px';
            break;
        case 40: case 83: //bottom arrow
            divObj.style.top = (parseInt(top) + 5) + 'px';
            break;

    }
}

// Tweetable Konami codevar
var k=[];
function(e){
    k.push(e.keyCode);
    if(k.toString().indexOf("38,38,40,40,37,39,37,39,66,65")>=0) {
        alert("Konami Code Activated");
    }
}

你可能感兴趣的:(JavaScript,UP,C,C++,C#)