18 #include "precompiled.h"
31 #if SDL_VERSION_ATLEAST(2, 0, 0)
32 #define SDLKEY SDL_Keycode
68 multikeyParser.
InputTaskType(
"multikey",
"<[~$arg(_negate)]$value_+_>_[~$arg(_negate)]$value" );
70 for( std::map<CStr, CConfigValueSet>::iterator bindingsIt = bindings.begin(); bindingsIt != bindings.end(); ++bindingsIt )
72 std::string hotkeyName = bindingsIt->first.substr(7);
74 for( CConfigValueSet::iterator it = bindingsIt->second.begin(); it != bindingsIt->second.end(); ++it )
77 if( it->GetString( hotkey ) )
79 std::vector<SKey> keyCombination;
82 multikeyIdentifier.
ParseString( multikeyParser, hotkey );
86 bool negateNext =
false;
88 for(
size_t t = 0; t < multikeyIdentifier.
GetArgCount(); t++ )
93 if( hotkey ==
"_negate" )
110 LOGWARNING(L
"Hotkey mapping used invalid key '%hs'", hotkey.c_str() );
115 keyCombination.push_back(key);
122 std::vector<SKey>::iterator itKey, itKey2;
124 for( itKey = keyCombination.begin(); itKey != keyCombination.end(); ++itKey )
128 bindCode.
name = hotkeyName;
129 bindCode.
negated = itKey->negated;
131 for( itKey2 = keyCombination.begin(); itKey2 != keyCombination.end(); ++itKey2 )
134 if( itKey != itKey2 )
135 bindCode.
requires.push_back( *itKey2 );
154 for( std::map<int, KeyMapping>::iterator mapIt =
g_HotkeyMap.begin(); mapIt !=
g_HotkeyMap.end(); ++mapIt )
158 for( std::vector<SHotkeyMapping>::iterator it = hotkeyMap.begin(); it != hotkeyMap.end(); ++it )
163 bool allNegated =
true;
165 for( std::vector<SKey>::iterator j = it->requires.begin(); j != it->requires.end(); ++j )
201 #if SDL_VERSION_ATLEAST(2, 0, 0)
203 if (ev->
ev.wheel.y > 0)
208 else if (ev->
ev.wheel.y < 0)
231 if( ( keycode == SDLK_LSHIFT ) || ( keycode == SDLK_RSHIFT ) )
237 else if( ( keycode == SDLK_LCTRL ) || ( keycode == SDLK_RCTRL ) )
243 else if( ( keycode == SDLK_LALT ) || ( keycode == SDLK_RALT ) )
249 #if SDL_VERSION_ATLEAST(2, 0, 0)
250 else if( ( keycode == SDLK_LGUI ) || ( keycode == SDLK_RGUI ) )
252 else if( ( keycode == SDLK_LSUPER ) || ( keycode == SDLK_RSUPER ) || ( keycode == SDLK_LMETA ) || ( keycode == SDLK_RMETA) )
267 bool consoleCapture =
false;
270 consoleCapture =
true;
282 #if SDL_VERSION_ATLEAST(2, 0, 0)
290 std::vector<const char*> closestMapNames;
291 size_t closestMapMatch = 0;
293 for( std::vector<SHotkeyMapping>::iterator it =
g_HotkeyMap[keycode].begin(); it <
g_HotkeyMap[keycode].end(); ++it )
297 if( it->negated == typeKeyDown )
304 for( std::vector<SKey>::iterator itKey = it->requires.begin(); itKey != it->requires.end(); ++itKey )
306 bool rqdState = !itKey->negated;
310 if(
g_keys[itKey->code] != rqdState ) accept =
false;
322 if( accept && !( consoleCapture && it->name !=
"console.toggle" ) )
329 if( it->requires.size() + 1 >= closestMapMatch )
332 if( it->requires.size() + 1 > closestMapMatch )
335 closestMapNames.clear();
336 closestMapMatch = it->requires.size() + 1;
339 closestMapNames.push_back(it->name.c_str());
344 for (
size_t i = 0; i < closestMapNames.size(); ++i)
350 hotkeyNotification.
user.
data1 =
const_cast<char*
>(closestMapNames[i]);
356 for( std::vector<SHotkeyMapping>::iterator it =
g_HotkeyMap[keycode].begin(); it <
g_HotkeyMap[keycode].end(); ++it )
362 if( it->negated != typeKeyDown )
369 for( std::vector<SKey>::iterator itKey = it->requires.begin(); itKey != it->requires.end(); ++itKey )
371 bool rqdState = !itKey->negated;
375 if(
g_keys[itKey->code] != rqdState ) accept =
false;
392 hotkeyNotification.
user.
data1 =
const_cast<char*
>(it->name.c_str());
#define CUSTOM_SDL_KEYCODE
int FindKeyCode(const CStr &keyname)
static bool unified[UNIFIED_LAST-UNIFIED_SHIFT]
#define SDL_VERSION_ATLEAST(X, Y, Z)
std::vector< SHotkeyMapping > KeyMapping
SDL_MouseButtonEvent button
static std::map< int, KeyMapping > g_HotkeyMap
static void LoadConfigBindings()
bool g_mouse_buttons[6]
g_mouse_buttons: Mouse buttons states, indexed by SDL_BUTTON_* constants.
std::map< std::string, bool > g_HotkeyStatus
bool ParseString(const CParser &parser, const std::string &line)
bool GetArgString(size_t arg, std::string &ret)
InReaction HotkeyInputHandler(const SDL_Event_ *ev)
size_t GetArgCount() const
bool InputTaskType(const std::string &strName, const std::string &strSyntax)
int SDL_PushEvent(SDL_Event *ev)
bool HotkeyIsPressed(const CStr &keyname)
std::vector< SKey > requires
std::map< int32_t, bool > g_keys
g_keys: Key states, indexed by SDLK* constants.