know the time a key is pressed js code example Example: js when key is pressed document.addEventListener("keypress", function(event) { // do stuff });