CancelImage Upload

How to detect what key has been pressed on key up with JavaScript

While the event onkeyup detects the instance when a user presses a key, by itself we will not know which key has been pressed. For this we will need to consult the event object to find out the Unicode of the key in question. Here is the code with which this task can be accomplished:


Through event keyCode then we will receive the Unicode number corresponding to our key. By adding the amp and number symbol before, and a semicolon after the number we can go one step further and actually find out what the key in question looks like in human readable form:

<title>How to detect what key has been pressed on key up with JavaScript</title>
<script type="text/javascript">

function loadKey(event)

       var keys = document.getElementById("keys");

       keys.innerHTML = "&#" + event.keyCode + ";";



<body onkeyup="loadKey(event)">

<span id="keys"></span>


Want to leave a comment?

No problem. Just enter your email and password below.

register | home | reminder

myDesignTool Networking •