Fixed remapping virtual keys, closes #415
parent
8f78dc81e7
commit
e179847358
|
@ -70,6 +70,7 @@ set(BASE_SOURCES
|
|||
common/event.cpp
|
||||
common/image.cpp
|
||||
common/iman.cpp
|
||||
common/key.cpp
|
||||
common/logger.cpp
|
||||
common/misc.cpp
|
||||
common/pathman.cpp
|
||||
|
|
|
@ -1189,17 +1189,10 @@ Event CApplication::CreateVirtualEvent(const Event& sourceEvent)
|
|||
{
|
||||
virtualEvent.type = sourceEvent.type;
|
||||
virtualEvent.key = sourceEvent.key;
|
||||
virtualEvent.key.key = GetVirtualKey(sourceEvent.key.key);
|
||||
virtualEvent.key.virt = true;
|
||||
|
||||
if (sourceEvent.key.key == KEY(LCTRL) || sourceEvent.key.key == KEY(RCTRL))
|
||||
virtualEvent.key.key = VIRTUAL_KMOD(CTRL);
|
||||
else if (sourceEvent.key.key == KEY(LSHIFT) || sourceEvent.key.key == KEY(RSHIFT))
|
||||
virtualEvent.key.key = VIRTUAL_KMOD(SHIFT);
|
||||
else if (sourceEvent.key.key == KEY(LALT) || sourceEvent.key.key == KEY(RALT))
|
||||
virtualEvent.key.key = VIRTUAL_KMOD(ALT);
|
||||
else if (sourceEvent.key.key == KEY(LMETA) || sourceEvent.key.key == KEY(RMETA))
|
||||
virtualEvent.key.key = VIRTUAL_KMOD(META);
|
||||
else
|
||||
if(virtualEvent.key.key == sourceEvent.key.key)
|
||||
virtualEvent.type = EVENT_NULL;
|
||||
}
|
||||
else if ((sourceEvent.type == EVENT_JOY_BUTTON_DOWN) || (sourceEvent.type == EVENT_JOY_BUTTON_UP))
|
||||
|
|
|
@ -0,0 +1,37 @@
|
|||
/*
|
||||
* This file is part of the Colobot: Gold Edition source code
|
||||
* Copyright (C) 2001-2015, Daniel Roux, EPSITEC SA & TerranovaTeam
|
||||
* http://epsiteс.ch; http://colobot.info; http://github.com/colobot
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
|
||||
* See the GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see http://gnu.org/licenses
|
||||
*/
|
||||
|
||||
#include "common/key.h"
|
||||
|
||||
unsigned int GetVirtualKey(unsigned int key)
|
||||
{
|
||||
if(key == KEY(LCTRL) || key == KEY(RCTRL))
|
||||
return VIRTUAL_KMOD(CTRL);
|
||||
if(key == KEY(LSHIFT) || key == KEY(RSHIFT))
|
||||
return VIRTUAL_KMOD(SHIFT);
|
||||
if(key == KEY(LALT) || key == KEY(RALT))
|
||||
return VIRTUAL_KMOD(ALT);
|
||||
if(key == KEY(LMETA) || key == KEY(RMETA))
|
||||
return VIRTUAL_KMOD(META);
|
||||
|
||||
if(key == KEY(KP_ENTER))
|
||||
return KEY(RETURN);
|
||||
|
||||
return key;
|
||||
}
|
|
@ -58,6 +58,9 @@ enum VirtualKmod
|
|||
// So it is the same as other macros
|
||||
#define VIRTUAL_KMOD(x) VIRTUAL_KMOD_ ## x
|
||||
|
||||
//! Converts individual codes to virtual keys if needed
|
||||
unsigned int GetVirtualKey(unsigned int key);
|
||||
|
||||
// Virtual key code generated on joystick button presses
|
||||
// num is number of joystick button
|
||||
#define VIRTUAL_JOY(num) (SDLK_LAST + 200 + num)
|
||||
|
|
|
@ -70,22 +70,23 @@ bool CKey::EventProcess(const Event &event)
|
|||
if (event.type == EVENT_KEY_DOWN && m_catch)
|
||||
{
|
||||
m_catch = false;
|
||||
unsigned int key = GetVirtualKey(event.key.key);
|
||||
|
||||
if (TestKey(event.key.key)) // impossible ?
|
||||
if (TestKey(key)) // impossible ?
|
||||
{
|
||||
m_sound->Play(SOUND_TZOING);
|
||||
}
|
||||
else
|
||||
{
|
||||
if (event.key.key == m_binding.primary || event.key.key == m_binding.secondary)
|
||||
if (key == m_binding.primary || key == m_binding.secondary)
|
||||
{
|
||||
m_binding.secondary = KEY_INVALID;
|
||||
m_binding.primary = event.key.key;
|
||||
m_binding.primary = key;
|
||||
}
|
||||
else
|
||||
{
|
||||
m_binding.secondary = m_binding.primary;
|
||||
m_binding.primary = event.key.key;
|
||||
m_binding.primary = key;
|
||||
}
|
||||
m_sound->Play(SOUND_CLICK);
|
||||
|
||||
|
|
Loading…
Reference in New Issue