我在这里看到一些类似的问题(如JavaScript: Check if CTRL button was pressed),但我的问题实际上是事件触发。我的js代码:javascript - 检测按键或按下按键,按键事件不会触发
// Listen to keyboard.
window.onkeypress = listenToTheKey;
window.onkeyup = listenToKeyUp;
/*
Gets the key pressed and send a request to the associated function
@input key
*/
function listenToTheKey(e)
{
if (editFlag == 0)
{
// If delete key is pressed calls delete
if (e.keyCode == 46)
deleteNode();
// If insert key is pressed calls add blank
if (e.keyCode == 45)
createBlank();
if (e.keyCode == 17)
ctrlFlag = 1;
}
}
事件引发了除CTRL任何其他键。
我还需要触发它为ctrl。
我不能使用jQuery/prototype/whatever,所以这些解决方案是不可接受的。
所以...我怎么能检测到ctrl?
不是这样的:if(e.ctrlKey){....} work ..? – 2012-02-21 09:26:01