Jump to content

trouble with keycode handling.


ginerjm
Go to solution Solved by ginerjm,

Recommended Posts

I"m using the following code to detect and interpret numeric inputs:

 

 function handleTimeEntry(event)
 {
  var obj = event.target||event.srcElement;
  var kycode = event.keyCode;
  var ky = String.fromCharCode(kycode);
  alert("got kycode of "+kycode+ " leading to ky of "+ky);
blah,blah,blah

 

}

 

When I use the normal number keys - no problem.  But when I use my numeric keypad at the end of my keyboard I get the following:

 

(with num lock on):  a 1 keypress returns a kycode = 97 and ky = a  which my script rejects as non-numeric.  Other keys do similar 'wrong' things.

(with num lock off):  a 1 keypress returns a kycode =35 and ky = # which is also rejected.

 

According to the keycode charts I've read online, the kycode values I'm getting are correct with numlock on according to the stenciled characters that are on the keys I'm hitting, but the result of "fromCharCode(kycode)" is not what I should be getting.

 

Ideas?

Link to comment
Share on other sites

As you see, I'm capturing individual keystrokes.  The purpose is to monitor data entry and modify the input as it happens.  Can regex be used for that purpose?  Specifically I'm capturing day and time values and trying to do it all numerically to lessen the load on the person doing the input.  So instead of having to type "Fri. 05:00"  as an example, they need only type 10500  which gets modified as follows:

1 -> Fri.

0 -> Fri. 0

5 -> Fri. 05

0 -> Fri. 05:0

0 -> Fri. 05:00

 

The use of the numeric keypad is crucial in this situation - to not be able to handle it would be a great weakness in my appl.

 

So getting back to my question - why does my JS not recognize the number keypad's inputs properly?

Link to comment
Share on other sites

  • Solution

OK - I changed the way I'm determinging the numeric value of my keyup result to use two arrays - one for normal number keycodes and another for the numeric keypad keycodes.  My input is being processing properly now.

 

Please see my new post on how to convert an Enter key to a tab keystroke if you would like to assist me there.  :)

 

Consider my problem closed.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.