0

I wondered which numbers represent which keys on your keyboard, for example, I know 65 represents a, but which number would represents s?

I couldn't find it anywhere. If I didn't search like I should have, please redirect me.

Thanks in advance.

David Thomas
  • 249,100
  • 51
  • 377
  • 410

3 Answers3

2

Well, I had a few minutes and so I wrote this (which should allow you to find the key-code of any given key, or keys, on your keyboard):

function keyMap(start, stop) {
    var startFrom, stopAt, o = {};

    // doing different things, depending on what the 'start' variable is:
    switch (typeof start) {
        // if it's a string, we need the character-code, so we get that:
        case 'string':
            startFrom = start.charCodeAt(0);
            break;
        // if it's already a number, we use that as-is:
        case 'number':
            startFrom = start;
            break;
        // whatever else it might be, we quit here:
        default:
            return '';
    }

    // similarly for the 'stop' variable:
    switch (typeof stop) {
        case 'string':
            stopAt = stop.charCodeAt(0);
            break;
        case 'number':
            stopAt = stop;
            break;
        // if it's neither a number, nor a string,
        default:
            /* but start has a length of at least 2, and start is a string,
               we use the second character of the start string, or
               we simply add 1 to the character-code from the start variable: */
            stopAt = start.length > 1 && typeof start === 'string' ? start.charCodeAt(1) : startFrom;
            break;
    }

    /* iterate over the character-codes (using 'len = stopAt + 1 because we
       want to include the ending character): */
    for (var i = startFrom, len = stopAt + 1; i < len; i++) {
        // setting the keys of the 'o' map, and the value stored therein:
        o[String.fromCharCode(i)] = i;
    }
    return o;
}

var map = keyMap('s');
console.log(map, map['s'], map.s);

JS Fiddle demo.

Or, to find a range of keycodes:

var map = keyMap('a','z');
console.log(map, map.a, map.b, map.c /* ...and so on... */);

JS Fiddle demo.

Or, to find the same range, but with only one supplied argument:

var map = keyMap('az');
console.log(map, map.a, map.b, map.c /* ...and so on... */);

JS Fiddle demo.

References:

David Thomas
  • 249,100
  • 51
  • 377
  • 410
1

Look at the Decimal values in The ascii table HERE. Lower-case s is 115.

Bram Vanroy
  • 27,032
  • 24
  • 137
  • 239
Stphane
  • 3,368
  • 5
  • 32
  • 47
0

here is the link to all the keyCodes.. however you can always try it yourself ..

using jquery

$(document).keyup(function(e){
  alert(e.keyCode);
  //or
  alert(e.which);
})

fiddle here

bipen
  • 36,319
  • 9
  • 49
  • 62
  • you can use e.which or e.keyCode , with jquery it is normalized.. so doesnot matter... – bipen Oct 19 '13 at 17:55
  • Saw this in documentation page `"The event.which property normalizes event.keyCode and event.charCode. It is recommended to watch event.which for keyboard key input."` – Stphane Oct 19 '13 at 17:58
  • yaaa.. already added that to answer too.. :) ...as said it is normalized with jquery so i guess we can reliably use both ... – bipen Oct 19 '13 at 18:03
  • 1
    My bad, I did not read the article `:p` – Stphane Oct 19 '13 at 18:05