我看到这里有一些类似的问题(比如JavaScript:检查是否按下了CTRL键),但我的问题实际上是事件触发。我的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/任何其他解决方案,因此这些解决方案不可接受。
那么...我如何检测ctrl?