Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Can I determine which key was previously pressed? JavaScript

Can I determine which key was previously pressed?

$("#divex").keypress(getKey);

    function getKey(e)
    {
       //alert previous key pressed to e ???
       alert(e.which); //gets current key ascii code
    }
like image 750
mircea . Avatar asked Jul 06 '26 01:07

mircea .


1 Answers

You can store it in a variable:

var prevKey = null;

$("#divex").keypress(getKey);

function getKey(e)
{
   if (prevKey !== null) alert(prevKey);
   prevKey = e.which;
   alert(e.which); //gets current key ascii code
}
like image 114
Sarfraz Avatar answered Jul 08 '26 16:07

Sarfraz



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!