mirror of
https://github.com/ddnet/ddnet.git
synced 2024-11-19 14:38:18 +00:00
Fix e.g. key press lshift being treated as shift+lshift
This commit is contained in:
parent
5194cf66fe
commit
577ce2ba25
|
@ -59,6 +59,23 @@ int CBinds::GetModifierMask(IInput *i)
|
|||
return Mask;
|
||||
}
|
||||
|
||||
int CBinds::GetModifierMaskOfKey(int Key)
|
||||
{
|
||||
switch(Key)
|
||||
{
|
||||
case KEY_LSHIFT:
|
||||
case KEY_RSHIFT:
|
||||
return 1 << CBinds::MODIFIER_SHIFT;
|
||||
case KEY_LCTRL:
|
||||
case KEY_RCTRL:
|
||||
return 1 << CBinds::MODIFIER_CTRL;
|
||||
case KEY_LALT:
|
||||
return 1 << CBinds::MODIFIER_ALT;
|
||||
default:
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
bool CBinds::ModifierMatchesKey(int Modifier, int Key)
|
||||
{
|
||||
switch(Modifier)
|
||||
|
@ -100,12 +117,20 @@ bool CBinds::CBindsSpecial::OnInput(IInput::CEvent Event)
|
|||
|
||||
bool CBinds::OnInput(IInput::CEvent Event)
|
||||
{
|
||||
int Mask = GetModifierMask(Input());
|
||||
|
||||
// don't handle invalid events and keys that aren't set to anything
|
||||
if(Event.m_Key <= 0 || Event.m_Key >= KEY_LAST)
|
||||
return false;
|
||||
|
||||
int Mask = GetModifierMask(Input());
|
||||
int KeyModifierMask = GetModifierMaskOfKey(Event.m_Key); // returns 0 if m_Key is not a modifier
|
||||
if(KeyModifierMask)
|
||||
{
|
||||
// avoid to have e.g. key press "lshift" be treated as "shift+lshift"
|
||||
Mask -= KeyModifierMask;
|
||||
if(!Mask)
|
||||
Mask = 1 << MODIFIER_NONE;
|
||||
}
|
||||
|
||||
bool rtn = false;
|
||||
for(int m = 0; m < MODIFIER_COUNT; m++)
|
||||
{
|
||||
|
|
|
@ -45,6 +45,7 @@ public:
|
|||
void GetKey(const char *pBindStr, char aBuf[64], unsigned BufSize);
|
||||
static const char *GetModifierName(int m);
|
||||
static int GetModifierMask(IInput *i);
|
||||
static int GetModifierMaskOfKey(int Key);
|
||||
static bool ModifierMatchesKey(int Modifier, int Key);
|
||||
|
||||
virtual void OnConsoleInit();
|
||||
|
|
Loading…
Reference in a new issue