faqts : Computers : Programming : Languages : JavaScript : Event handling

+ Search
Add Entry AlertManage Folder Edit Entry Add page to http://del.icio.us/
Did You Find This Entry Useful?

26 of 27 people (96%) answered Yes
Recently 10 of 10 people (100%) answered Yes

Entry

How do I capture keystroke values into an array?

Apr 30th, 2000 07:53
Martin Honnen, Imran Mohamed Noor,


Well, you look around on JavaScript.FAQTs.com on how to capture key 
events:
http://www.faqts.com/knowledge-base/view.phtml/aid/1189/fid/145/lang/
and then you just need to define an array to which to add the keys when 
the event occurs; the following is an example which displays the array 
in the status bar
<HTML>
<HEAD>
<SCRIPT>
var capturedKeys = new Array();
if (document.layers)
  document.captureEvents(Event.KEYPRESS);
document.onkeypress = function (evt) {
  var key =
    document.layers ? evt.which :
    document.all ? event.keyCode :
    (evt.which || evt.charCode || evt.keyCode);
  if (key >= 32)
    capturedKeys[capturedKeys.length] = String.fromCharCode(key);
  window.status = capturedKeys;
  return true;
}
</SCRIPT>
</HEAD>
<BODY>
</BODY>
</HTML>