diff options
author | Behdad Esfahbod <behdad@behdad.org> | 2012-04-04 02:13:00 -0400 |
---|---|---|
committer | Behdad Esfahbod <behdad@behdad.org> | 2012-04-04 02:13:00 -0400 |
commit | 1ccaed4533a290829db181d8398d0879b5f3bff1 (patch) | |
tree | 040c817a312d00b93d367f0115505d512ae83055 /src/library_glut.js | |
parent | c2611d1d61cf4da9da714b90ffe27c2ac7b4aa9a (diff) |
Flesh out GLUT keyboard funcs
Diffstat (limited to 'src/library_glut.js')
-rw-r--r-- | src/library_glut.js | 35 |
1 files changed, 33 insertions, 2 deletions
diff --git a/src/library_glut.js b/src/library_glut.js index d5608ee8..363f417f 100644 --- a/src/library_glut.js +++ b/src/library_glut.js @@ -69,8 +69,39 @@ var LibraryGLUT = { }, getASCIIKey: function(event) { - // TODO apply modifiers, etc - return event['keyCode']; + var keycode = event['keyCode']; + + /* The exact list is soooo hard to find in a canonical place! */ + + if (48 <= keycode && keycode <= 57) + return keycode; // numeric + if (65 <= keycode && keycode <= 90) + return event['shiftKey'] ? keycode : keycode + 32; + if (106 <= keycode && keycode <= 111) + return keycode - 106 + 42; // *,+-./ + + switch (keycode) { + case 27: // escape + case 32: // space + case 61: // equal + return keycode; + } + + var s = event['shiftKey']; + switch (keycode) { + case 186: return s ? 58 : 59; // colon / semi-colon + case 187: return s ? 43 : 61; // add / equal (these two may be wrong) + case 188: return s ? 60 : 44; // less-than / comma + case 189: return s ? 95 : 45; // dash + case 190: return s ? 62 : 46; // greater-than / period + case 191: return s ? 63 : 47; // forward slash + case 219: return s ? 123 : 91; // open bracket + case 220: return s ? 124 : 47; // back slash + case 221: return s ? 125 : 93; // close braket + case 222: return s ? 34 : 39; // single quote + } + + return null; }, onKeydown: function(event) { |