0

How can I list all available keyboard characters with JavaScript or|and PHP?

Lets say that user doesn't have access to the keyboard and can only fill a form with the mouse. I want to list all available keyboard characters to bind them to the mouse click event.

EDIT:

I don't care what kind of keyboard user has. What I know is that Alt + 0246 gets ö as @Barney sad. Where is that ö stored so that some keyboards access that character from a key and others with ALT + 0246? Isn't that location like an array accessible by PHP|JavaScript?

Alqin
  • 1,305
  • 3
  • 16
  • 35
  • You cannot know what kind of keyboard the user has - therefore, I for example have `æ`, `ø` and `å` but not `ä` and `ö` and most people have non of those. Check out this for more info: http://stackoverflow.com/questions/8892238/detect-keyboard-layout-with-javascript – h2ooooooo Feb 28 '13 at 11:52
  • Say what now? Are you talking about a virtual keyboard, like on phones and Google? I also have æøå, so that's two for two, which means you should definitely go for a Scandinavian keyboard! – adeneo Feb 28 '13 at 11:52

3 Answers3

0

Impossible to detect what keyboard the user has from within the browser context — this is the cause of a whole host of problems, as helpfully described here — which means we can't tell what characters are directly inputtable by the user.

As an example, German and Turkish users probably have ö readily available. I had to hold Alt and hit 0246 in sequence on my number pad to produce it. The end result is the same.

The other thing to bear in mind is that, even if you can determine exactly which key was hit, what it means and does is another thing entirely. The user could have rebound their commands at many junctures, or may be using a regional emulator.

Barney
  • 16,181
  • 5
  • 62
  • 76
0

Try something like this:

var container = $('#container');

for ( var i = 0; i < 26; i++ ) {
    var chr = $('<div>' + String.fromCharCode(97 + i) + '</div>');

    container.append(chr);
    chr.click(function() {
        console.log($(this).text());
    });
}
Eugene Manuilov
  • 4,271
  • 8
  • 32
  • 48