How can I display keycode in html div using function event
and document.onkeydown
. I need solution working on IE
Asked
Active
Viewed 40 times
-1

worker555
- 11
-
yeah not found exactly my solution on older version of IE I tryed change this code but not working https://stackoverflow.com/questions/1846599/how-to-find-out-what-character-key-is-pressed – worker555 Apr 12 '19 at 06:16
-
1cool, so you have done some research, from next time onwards, please add it along with your question. Questions without research efforts are not very welcomed here in SO – Krishna Prashatt Apr 12 '19 at 06:20
-
Hi worker555, welcome to SO. When asking questions, please refer to the [How-To-Ask](https://stackoverflow.com/help/how-to-ask) guide so that we are able to answer your questions as precisely and accordingly to meet your question's requirements. @KrishnaPrashatt No need to be rude toward new contributors. – Barrosy Apr 12 '19 at 07:56
1 Answers
1
For example this way:
var outputDiv = document.querySelector('#output');
function onKeyDown (e) {
outputDiv.innerHTML = e.which || e.keyCode;
}
document.onkeydown = onKeyDown;
// modern solution: document.addEventListener('keydown', onKeyDown);
#output {
padding: 10px;
background: #efefef;
}
<div id="output">Press a key</div>

David
- 3,552
- 1
- 13
- 24