Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

<b> Key Codes...

Status
Not open for further replies.

CuriousGuy

Programmer
Nov 29, 2002
17
US
IN the article :
thread216-417208 is a method for detecting if the user presses the enter key, as in the code below :

<script>
function checkKey(what){
what=window.event;
if (what.keyCode==13){alert('You pressed Enter!')}
else
alert('Not the right password')
}
document.onkeypress=checkKey;
</script>

Note that the key code for Enter is 13 (i.e. The code for Space and so forth), does anyone know where the other key codes are available.
Any help would be much appreciated
 
Ask Internet Explorer --
Code:
  var aK = new Array(2)
  aKClr()

function getKeyCode(state) { 
  aK[state] = event.keyCode
}

function aKShow() {
  alert(&quot;keyDown &quot;+aK[0]+&quot;\nkeyPress &quot;+aK[1]+&quot;\nkeyUp &quot;+aK[2])
  aKClr()
}

function aKClr() {
  for (var i = 0; i < aK.length; i++) {
    aK[i] = -1
    }
}
called by --
Code:
<body onload=&quot;document.all.pcIn.focus();&quot;>
Type a key
<input type=&quot;text&quot; id=&quot;pcIn&quot; maxlength=&quot;1&quot; size=&quot;1&quot;
  onkeydown=&quot;getKeyCode(0);&quot; onkeypress=&quot;getKeyCode(1);&quot;
  onkeyup = &quot;getKeyCode(2);aKShow();this.value = '';&quot; />

Shows what the browser is seeing at KeyDown, KeyPress, KeyUp. 'Course if someone else grabs your keystroke (F1 belongs to IE, CTL+ALT+DEL gets Window's attention ...) then you get their response.

(I've had this for a while. Could probably update it using the DOM ...)
 
Thank you very much <i> wray </i>, it works perfectly
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top