Qui vedo alcune domande simili (come JavaScript: Check if CTRL button was pressed) ma il mio problema è in realtà l'attivazione dell'evento. Il mio codice js:javascript - rileva il tasto ctrl premuto o su, l'evento keypress non si attiva
// 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;
}
}
L'evento attiva per tutti gli altri tasti ad eccezione del ctrl.
Devo anche attivarlo per ctrl.
Non riesco a utilizzare jQuery/prototipo/qualsiasi, quindi tali soluzioni non sono accettabili.
Quindi ... come posso rilevare lo ctrl?
no: if (e.ctrlKey) {....} funziona ..? –