Project::OSiRiON - Git repositories
Project::OSiRiON
News . About . Screenshots . Downloads . Forum . Wiki . Tracker . Git
summaryrefslogtreecommitdiff
blob: 45e928478fecc63f71193ef92c2136c55ba2977f (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
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