我在这里看到了一些类似的问题(比如JavaScript: Check if CTRL button was pressed),但我的问题实际上是事件触发。我的js代码:
// 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?