28 #include "gldrv/winsys.h"
31 static void DefaultKBHandler(
const KBData&,
KBSTATE newState )
41 function = DefaultKBHandler;
48 static void kbGetInput(
int key,
int modifiers,
bool release,
int x,
int y )
51 if (key < 0 || key >= WSK_LAST)
56 keyBindings[modifiers][key].
function( keyBindings[modifiers][key].data,
PRESS );
58 keyBindings[modifiers][key].
function( keyBindings[modifiers][key].data,
RELEASE );
63 static bool kbHasBinding(
int key,
int modifiers )
69 static const char _lomap[] =
"0123456789-=\';/.,`\\";
70 static const char _himap[] =
")!@#$%^&*(_+\":?><~|";
74 if ( ch == (ch&0xFF) ) {
75 const char *c = strchr( _lomap, ch );
77 return _himap[c-_lomap];
85 if ( ch == (ch&0xFF) ) {
86 const char *c = strchr( _himap, ch );
88 return _lomap[c-_himap];
94 static unsigned int _activeModifiers = 0;
98 _activeModifiers = mask;
101 void setActiveModifiersSDL( SDLMod mask )
104 ( ( mask&(KMOD_LSHIFT|KMOD_RSHIFT) ) ?
KB_MOD_SHIFT : 0 )
105 |( ( mask&(KMOD_LCTRL|KMOD_RCTRL) ) ?
KB_MOD_CTRL : 0 )
106 |( ( mask&(KMOD_LALT|KMOD_RALT) ) ?
KB_MOD_ALT : 0 ) );
111 return _activeModifiers;
116 setActiveModifiersSDL( SDL_GetModState() );
122 if (mod_name[0] ==
'\0')
125 if ( strstr( mod_name,
"shift" ) || strstr( mod_name,
"uppercase" ) || strstr( mod_name,
"caps" ) )
127 if ( strstr( mod_name,
"ctrl" ) || strstr( mod_name,
"cntrl" ) || strstr( mod_name,
"control" ) )
129 if ( strstr( mod_name,
"alt" ) || strstr( mod_name,
"alternate" ) )
135 return cntrlon ? KB_MOD_CTRL : ( alton ?
KB_MOD_ALT : (shifton ? KB_MOD_SHIFT : 0) );
139 bool shifton =
false;
144 if ( ( WSK_MOD_LSHIFT == (mod&WSK_MOD_LSHIFT) ) || ( WSK_MOD_RSHIFT == (mod&WSK_MOD_RSHIFT) ) ) {
147 if ( !kbHasBinding( ch, KB_MOD_SHIFT ) ) {
149 modmask &= ~KB_MOD_SHIFT;
153 if ( ( WSK_MOD_LALT == (mod&WSK_MOD_LALT) ) || ( WSK_MOD_RALT == (mod&WSK_MOD_RALT) ) )
155 if ( ( WSK_MOD_LCTRL == (mod&WSK_MOD_LCTRL) ) || ( WSK_MOD_RCTRL == (mod&WSK_MOD_RCTRL) ) )
159 (shifton ? KB_MOD_SHIFT : 0)
161 |(ctrlon ? KB_MOD_CTRL : 0) );
163 int curmod =
getModifier( alton, ctrlon, shifton )&modmask;
164 kbGetInput( ch, curmod, release, x, y );
169 kbGetInput(
shiftdown( ch ), i, release, x, y );
171 kbGetInput(
shiftup( ch ), i, release, x, y );
175 kbGetInput(
shiftdown( ch ), i, release, x, y );
177 kbGetInput(
shiftup( ch ), i, release, x, y );
209 if (playerBindings[mod][a] == player)
215 keyBindings[mod][key].
function = handler;
216 keyBindings[mod][key].
data = data;
217 playerBindings[mod][key] = player;
218 handler( std::string(),
RESET );