How to check state onKeypress

72 views Asked by At

I have simpy question..

How can take a state key (keydown, keyup) in onkeypress in Javascript?

document.onkeypress = function()
{
  console.log(/* STATE (down or up sometihn like this*/)
}
1

There are 1 answers

0
Tiago Mateus On

And if you have 2 functions? (up and down)

document.getElementById('my').onkeydown = function() {

    console.log('down');

}

document.getElementById('my').onkeyup = function() {
    console.log('up');
}