Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR JAVASCRIPT

how to detect the keyboard keys in js

With plain Javascript, the simplest is:
		document.onkeypress = function (e) {
    	e = e || window.event;
    	// use e.keyCode or whatever you want
};
You can Use the following too in Plain JS:
		document.addEventListener('keypress', function (e) {
    	e = e || window.event;
        // use e.keyCode or whatever you want
});
With jQuery:
		$(document).on("keypress", function (e) {
    	// use e.which
});
 
PREVIOUS NEXT
Tagged: #detect #keyboard #keys #js
ADD COMMENT
Topic
Name
2+3 =