I'm trying to write a web based app in JavaScript and I came across a little a little hurdle when trying to write a piece of code that returns either true or false depending on what key the user pressed.
Here is the code:
function getKey(key)
{
window.addEventListener("keydown", function(e) {
return e.keyCode === key;
});
}
This always returns 'undefined', and I can't get it to work. I would greatly appreciate if someone answered and fixed my little problem.
Thanks!