español ejemplos descargar definicion curso caracteristicas javascript

ejemplos - JavaScript: compruebe si se presionó el botón CTRL



javascript html (4)

Necesito comprobar si el botón CTRL fue presionado mientras hago clic en un control en mi página html usando JavaScript.

¿Cómo puedo hacer esto?


Intenta buscar en el objeto del evento.

p.ej

document.body.onclick = function (e) { if (e.ctrlKey) { alert("ctr key was pressed during the click"); } }


Lo hice usando la bandera global cntrlIsPressed; también se ocupa de seleccionar todas las opciones usando Control + A

// Check whether control button is pressed $(document).keydown(function(event) { if (event.which == "17") cntrlIsPressed = true; else if (event.which == 65 && cntrlIsPressed) { // Cntrl+ A selectAllRows(); } }); $(document).keyup(function() { cntrlIsPressed = false; }); var cntrlIsPressed = false;


Yo uso esto y funciona bien

<a href="" onclick="return Details(event)" ></a> function Details(event) { if (event.ctrlKey) { alert(''Ctrl down''); } }


echa un vistazo a la propiedad ctrlKey del evento