Project::OSiRiON - Git repositories
Project::OSiRiON
News . About . Screenshots . Downloads . Forum . Wiki . Tracker . Git
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorStijn Buys <ingar@osirion.org>2008-02-05 23:40:20 +0000
committerStijn Buys <ingar@osirion.org>2008-02-05 23:40:20 +0000
commit00a039fffea099eb53d2bbe77d3300b3d7ea768f (patch)
tree2255960b8f4b9c782502e9caa00703ffc134a6db /src/client/keyboard.cc
parent1ed2e8eb1f1909a35f6fc8d5d6065bcac37c27ea (diff)
make keyboard input actually work
Diffstat (limited to 'src/client/keyboard.cc')
-rw-r--r--src/client/keyboard.cc112
1 files changed, 112 insertions, 0 deletions
diff --git a/src/client/keyboard.cc b/src/client/keyboard.cc
new file mode 100644
index 0000000..45e9284
--- /dev/null
+++ b/src/client/keyboard.cc
@@ -0,0 +1,112 @@
+/*
+ client/keyboard.cc
+ This file is part of the Osirion project and is distributed under
+ the terms and conditions of the GNU General Public License version 2
+*/
+
+#include "client/keyboard.h"
+
+#include <iostream>
+
+namespace client {
+
+void setkeyboardmode(bool input)
+{
+ if(input)
+ SDL_EnableKeyRepeat(250, SDL_DEFAULT_REPEAT_INTERVAL);
+ else
+ SDL_EnableKeyRepeat(10, SDL_DEFAULT_REPEAT_INTERVAL);
+}
+
+char keysym_to_char(const SDL_keysym &keysym)
+{
+ char c = (char) keysym.sym;
+ bool shiftstate = false;
+
+ if (keysym.mod & KMOD_CAPS)
+ shiftstate = true;
+
+ if ((keysym.mod & KMOD_LSHIFT) || (keysym.mod & KMOD_RSHIFT)) {
+ shiftstate = !shiftstate;
+ }
+
+ if (!shiftstate)
+ return c;
+
+ if ((c >= 'a' && c <= 'z')) {
+ c = c + 'A' - 'a';
+ } else {
+ switch (c) {
+ case '`':
+ c = '~';
+ break;
+ case '1':
+ c = '!';
+ break;
+ case '2':
+ c = '@';
+ break;
+ case '3':
+ c = '#';
+ break;
+ case '4':
+ c = '$';
+ break;
+ case '5':
+ c = '%';
+ break;
+ case '6':
+ c = '^';
+ break;
+ case '7':
+ c = '&';
+ break;
+ case '8':
+ c = '*';
+ break;
+ case '9':
+ c = '(';
+ break;
+ case '0':
+ c = ')';
+ break;
+ case '-':
+ c = '_';
+ break;
+ case '=':
+ c = '+';
+ break;
+ // second row
+ case '[':
+ c = '{';
+ break;
+ case ']':
+ c = '}';
+ break;
+ case '|':
+ c = '\\';
+ break;
+ // third row
+ case ';':
+ c = ':';
+ break;
+ case '\'':
+ c = '"';
+ break;
+ // fourth row
+ case ',':
+ c = '<';
+ break;
+ case '.':
+ c = '>';
+ break;
+ case '/':
+ c = '?';
+ break;
+ }
+ }
+
+ return c;
+}
+
+} // namespace client