JavaScript keyboard events -Get Pressed key and Keycode
JavaScript keyboard events -Get Pressed key and Keycode |
you will learn about JavaScript onkeyup and onkeydown function..
you can catch which key are user pressing from their keyboard ..and you can also detect keycode for every key..
just copy the below codes and try how to get keycode,pressed key and keyboard event in javascript..
index.html
<!DOCTYPE html> <script> document.onkeydown = function(event) { var key_press = String.fromCharCode(event.keyCode); var key_code = event.keyCode; document.getElementById('keypress').innerHTML = key_press; document.getElementById('keycode').innerHTML = key_code; var status = document.getElementById('status'); status.innerHTML = "Down Key Pressed : "+key_press; } document.onkeyup = function(event){ var key_press = String.fromCharCode(event.keyCode); var status = document.getElementById('status'); status.innerHTML = "UP Key Pressed : "+key_press; } </script> <h1>JavaScript Capture Keyboard Event Example</h1> <h2>OnKeydown - OnKeyup</h2> Pressed Key: <div id="keypress"></div> <br /> Key Code : <div id="keycode"></div> <p id="status">Keyboard Event Status</p>
That's it friends about JavaScript keyboard events --get Pressed key and keycode ..if you you like this article please share with your friends..
Demo:: try it Your Self please press any key..
JavaScript Capture Keyboard Event Example
OnKeydown - OnKeyup
Pressed Key:Key Code :
Keyboard Event Status
No comments:
Post a Comment
Thank You for Your Comment
Note: Only a member of this blog may post a comment.