User B1KMusic からこの解決策を見つけました: JavaScript を使用して一度に複数のキーが押されたかどうかを検出するには?
コード:
map={}//I know most use an array, but the use of string indexes in arrays is questionable
onkeydown=onkeyup=function(e){
e=e||event//to deal with IE
map[e.keyCode]=e.type=='keydown'?true:false
/*insert conditional here*/
}
if(map[17]&&map[16]&&map[65]){//CTRL+SHIFT+A
alert('Control Shift A')
}else if(map[17]&&map[16]&&map[66]){//CTRL+SHIFT+B
alert('Control Shift B')
}else if(map[17]&&map[16]&&map[67]){//CTRL+SHIFT+C
alert('Control Shift C')
}
CTRLこれは機能しますが、問題があります。 + SHIFT+を押した後にアラートを受け取った後、B任意のキーを押すと、アラートが再び表示されます。
B1KMusic は次の作業を見つけました。
if(map[17]&&map[16]&&map[65]){//CTRL+SHIFT+A
alert('Oh noes, a bug!')
}
//When you Press any key after executing this, it will alert again, even though you
//are clearly NOT pressing CTRL+SHIFT+A
//The fix would look like this:
if(map[17]&&map[16]&&map[65]){//CTRL+SHIFT+A
alert('Take that, bug!')
map={}
}
//The bug no longer happens since the map object is cleared
これを試しましたが、まだ問題が発生します。