I want that if a user clicks D a functions gets executes after one second and if a person clicks A before the code in timeout is executed, I want it to wait for the code to get executed. I dont know if this is possible with code I wrote. If it's possible please let me know how to do it. Any help will be highly appreciable. JQuery can be used too.
$(document).keydown(function (e) {
// D click
if (e.key === 'd' || e.key === 'D') {
setTimeout(function () {
console.log('d clicked')
}, 1000)
}
// A click
else if (e.key === 'a' || e.key === 'A') {
console.log('a clicked')
}
});