键盘所有按键及键码的JSON数组

整理了一份键盘所有按键及其键码的数组,有用自取

[{“keyName”:“Backspace”,“keyCode”:8},{“keyName”:“Tab”,“keyCode”:9},{“keyName”:“Enter”,“keyCode”:13},{“keyName”:“Shift”,“keyCode”:16},{“keyName”:“Ctrl”,“keyCode”:17},{“keyName”:“Alt”,“keyCode”:18},{“keyName”:“Pause”,“keyCode”:19},{“keyName”:“Caps Lock”,“keyCode”:20},{“keyName”:“Esc”,“keyCode”:27},{“keyName”:“Space”,“keyCode”:32},{“keyName”:“Page Up”,“keyCode”:33},{“keyName”:“Page Down”,“keyCode”:34},{“keyName”:“End”,“keyCode”:35},{“keyName”:“Home”,“keyCode”:36},{“keyName”:“Left Arrow”,“keyCode”:37},{“keyName”:“Up Arrow”,“keyCode”:38},{“keyName”:“Right Arrow”,“keyCode”:39},{“keyName”:“Down Arrow”,“keyCode”:40},{“keyName”:“Insert”,“keyCode”:45},{“keyName”:“Delete”,“keyCode”:46},{“keyName”:“0”,“keyCode”:48},{“keyName”:“1”,“keyCode”:49},{“keyName”:“2”,“keyCode”:50},{“keyName”:“3”,“keyCode”:51},{“keyName”:“4”,“keyCode”:52},{“keyName”:“5”,“keyCode”:53},{“keyName”:“6”,“keyCode”:54},{“keyName”:“7”,“keyCode”:55},{“keyName”:“8”,“keyCode”:56},{“keyName”:“9”,“keyCode”:57},{“keyName”:“A”,“keyCode”:65},{“keyName”:“B”,“keyCode”:66},{“keyName”:“C”,“keyCode”:67},{“keyName”:“D”,“keyCode”:68},{“keyName”:“E”,“keyCode”:69},{“keyName”:“F”,“keyCode”:70},{“keyName”:“G”,“keyCode”:71},{“keyName”:“H”,“keyCode”:72},{“keyName”:“I”,“keyCode”:73},{“keyName”:“J”,“keyCode”:74},{“keyName”:“K”,“keyCode”:75},{“keyName”:“L”,“keyCode”:76},{“keyName”:“M”,“keyCode”:77},{“keyName”:“N”,“keyCode”:78},{“keyName”:“O”,“keyCode”:79},{“keyName”:“P”,“keyCode”:80},{“keyName”:“Q”,“keyCode”:81},{“keyName”:“R”,“keyCode”:82},{“keyName”:“S”,“keyCode”:83},{“keyName”:“T”,“keyCode”:84},{“keyName”:“U”,“keyCode”:85},{“keyName”:“V”,“keyCode”:86},{“keyName”:“W”,“keyCode”:87},{“keyName”:“X”,“keyCode”:88},{“keyName”:“Y”,“keyCode”:89},{“keyName”:“Z”,“keyCode”:90},{“keyName”:“LWin”,“keyCode”:91},{“keyName”:“RWin”,“keyCode”:92},{“keyName”:“Select Key”,“keyCode”:93},{“keyName”:“Numpad 0”,“keyCode”:96},{“keyName”:“Numpad 1”,“keyCode”:97},{“keyName”:“Numpad 2”,“keyCode”:98},{“keyName”:“Numpad 3”,“keyCode”:99},{“keyName”:“Numpad 4”,“keyCode”:100},{“keyName”:“Numpad 5”,“keyCode”:101},{“keyName”:“Numpad 6”,“keyCode”:102},{“keyName”:“Numpad 7”,“keyCode”:103},{“keyName”:“Numpad 8”,“keyCode”:104},{“keyName”:“Numpad 9”,“keyCode”:105},{“keyName”:“Multiply”,“keyCode”:106},{“keyName”:“Add”,“keyCode”:107},{“keyName”:“Subtract”,“keyCode”:109},{“keyName”:“Decimal Point”,“keyCode”:110},{“keyName”:“Divide”,“keyCode”:111},{“keyName”:“F1”,“keyCode”:112},{“keyName”:“F2”,“keyCode”:113},{“keyName”:“F3”,“keyCode”:114},{“keyName”:“F4”,“keyCode”:115},{“keyName”:“F5”,“keyCode”:116},{“keyName”:“F6”,“keyCode”:117},{“keyName”:“F7”,“keyCode”:118},{“keyName”:“F8”,“keyCode”:119},{“keyName”:“F9”,“keyCode”:120},{“keyName”:“F10”,“keyCode”:121},{“keyName”:“F11”,“keyCode”:122},{“keyName”:“F12”,“keyCode”:123},{“keyName”:“PrtSc”,“keyCode”:44},{“keyName”:“Num Lock”,“keyCode”:144},{“keyName”:“ScrLk”,“keyCode”:145},{“keyName”:“Pause”,“keyCode”:19},{“keyName”:“Semicolon”,“keyCode”:186},{“keyName”:“Equal Sign”,“keyCode”:187},{“keyName”:“Comma”,“keyCode”:188},{“keyName”:“Dash”,“keyCode”:189},{“keyName”:“Period”,“keyCode”:190},{“keyName”:“Forward Slash”,“keyCode”:191},{“keyName”:“Grave Accent”,“keyCode”:192},{“keyName”:“Open Bracket”,“keyCode”:219},{“keyName”:“Back Slash”,“keyCode”:220},{“keyName”:“Close Braket”,“keyCode”:221},{“keyName”:“Single Quote”,“keyCode”:222}]

几个重复按键的判断,注意,在键盘事件中keyCode即将废弃,请尽量使用which来代替

<script setup>
	// Vue3组合式API适用
	const handleKeyDown = e => {
	    let keyCode = e.which;
	    let location = e.location;
    	// 数字键盘区域的数字键
	    if (location === 3 && keyCode >= 96 && keyCode <= 105) {
	       
	    }
	    // 小键盘上的数字键,带有特殊符号的那一排
	    else if ((keyCode >= 48 && keyCode <= 57) || (keyCode >= 96 && keyCode <= 105)) {
	       
	    }// 右侧Shift\Alt\Crtl的判断
	    else if ((e.key=='Shift'||e.key=='Alt'||e.key=='Control')&&e.location=='2') {
	        
	    }// 右侧数字键盘区域Enter的判断
	    else if (e.key=='Enter'&&e.location=='3') {
	       
	    }//其它按键
	    else{
	        
	    }
	}
	onMounted(() => {
	    window.addEventListener('keydown', handleKeyDown)
	})
	
	onUnmounted(() => {
	    window.removeEventListener('keydown', handleKeyDown)
	})
</script>
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值