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 Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Capturing Keycode For Lowercase Character

Status
Not open for further replies.

SilverStray

Programmer
Oct 25, 2001
47
AU
Hi,

This kinda puzzles me, because when I try to capture the event.keyCode for a small letter 'a', it gives me the value of 65 which is for a capital 'A'. Why does Javascript seem to convert the keys I press into uppercase?

Similarly, I want to capture the keyCode for a dash ('-') and the event.keyCode equivalent it gave me was 189, when it's supposed to be 150. Probably because Javascript turned it to uppercase..but then again...why?

I am doing this because I want to write on a separate textbox any key that has been keypressed.

I hope somebody out there can help me with this.

Thanks in advance!

J. Echavez
 
I recently encountered this problem. In IE, I was able to solve it by checking if the shift key was being held down as:

Code:
function catchKey(field, evt)
{
 var x = event.keyCode;
 if(!event.shiftKey && (x>=65 && x<=90))
 {
  x += 32; //lower-case has keycode 32 higher than 
           // upper-case equivalents
 }
 return x;
}

Netscape has something called event.modifiers which I believe will lead you to whether or not the shift key is pressed, but I haven't used this before.

Plus, if javascript tells you the keycode for the dash is 189, then it is. Some of the keycodes seem to line up nicely with their unicode equivalents, but I guess not all.

'hope this'll get you started.

--Dave
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top