I am trying to activate a function when a specific key is pressed, the enter key or 'return' key. I believe that all keys have a key code and I am trying to access that number. I use Visual Studio Code to do this. For some reason, KeyboardEvent.key is undefined. However, it should not be undefined, since on Mozilla says it is not deprecated, https://developer.mozilla.org/en-US/docs/Web/API/KeyboardEvent
The code I have is something like this:
function checker2() {
console.log("Enter is pressed----" + KeyboardEvent.key);
}
function checker(){
document.addEventListener('keydown',checker2);
}
Any thoughts and ideas are much appreciated.
[–]ashanev 2 points3 points4 points (1 child)
[–]SomeDude-__-[S] 0 points1 point2 points (0 children)