Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

98
Vistas
how do i track key presses and log them to the console in Javascript

lately, I've started making a very simple program that I what to basically be a bunch of hotkeys for different JavaScript tags. But I don't know how to track the key presses and log them into the console.

about 4 years ago · Juan Pablo Isaza
2 Respuestas
Responde la pregunta

0

In HTML

<input type="text" id="username" onkeyup="myFunc()">

In Javascript

function myFunc(){
    console.log(document.getElementByID('username).value)
}
about 4 years ago · Juan Pablo Isaza Denunciar

0

in the whole window (to see the code snippet work, click Run code snippet then click in the blank area below and type some keys :) )

// list of modifiers : https://developer.mozilla.org/en-US/docs/Web/API/KeyboardEvent/getModifierState
var modifiers = ["CapsLock", "Control", "Alt", "Shift", "AltGraph"];
var upOrDown = function(event) {
    var element = document.getElementById("status");
    var key = event.key || event.which || event.keyCode; //find the key that was pressed
    var status = "Pressed :";
    for (const modifier of modifiers) {
        if (event.getModifierState(modifier))
        {
            status += " "+modifier;
        }
    }
    if ("keydown"==event.type && !modifiers.includes(key))
    {

        status += " "+key;
    }
    element.innerHTML = status;
    //console.log(status);
}
window.addEventListener("keydown",upOrDown,false);
window.addEventListener("keyup",upOrDown,false);
<div id="status">Pressed : </div>

about 4 years ago · Juan Pablo Isaza Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda