2020-05-26 23:47:03 +02:00
|
|
|
/* Copyright (C) 2020 Wildfire Games.
|
2009-04-18 19:00:33 +02:00
|
|
|
* This file is part of 0 A.D.
|
|
|
|
*
|
|
|
|
* 0 A.D. 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 2 of the License, or
|
|
|
|
* (at your option) any later version.
|
|
|
|
*
|
|
|
|
* 0 A.D. 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 0 A.D. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
*/
|
|
|
|
|
2004-07-21 18:51:21 +02:00
|
|
|
#include "precompiled.h"
|
|
|
|
#include "Hotkey.h"
|
2007-05-02 14:07:08 +02:00
|
|
|
|
2014-11-17 02:03:59 +01:00
|
|
|
#include <boost/tokenizer.hpp>
|
|
|
|
|
Let players remap hotkeys in-game, fix default hotkeys being qwerty-specific.
- Provide a "Hotkey" screen to let players remap hotkeys in-game using a
convenient setup.
- Make all .cfg hotkeys refer to scancodes (i.e. position on the
keyboard), so that default hotkeys now translate correctly for AZERTY,
QWERTZ and other layouts.
- 'BackSpace' is now an alias for 'Delete', and works for killing units.
This fixes #1917, as macs don't have a proper delete key and would need
to use Fn+Del otherwise. This shifts "timewarp" to Shift+BackSpace.
Functionally, this switches hotkeys to scancodes, as that makes more
sense (they are combinations of key positions, not actual text output).
SDL includes are cleaned and key names are reused.
Fixes #2850, Fixes #2604, Refs #1810, Fixes #1917.
Follows work in 3d7784d2af.
Various diffs tested by: Angen, Stan, Freagarach
Comments by: Nescio
Differential Revision: https://code.wildfiregames.com/D2814
This was SVN commit r24215.
2020-11-19 10:27:26 +01:00
|
|
|
#include "lib/external_libraries/libsdl.h"
|
2015-07-29 03:07:23 +02:00
|
|
|
#include "ps/CConsole.h"
|
|
|
|
#include "ps/CLogger.h"
|
|
|
|
#include "ps/CStr.h"
|
|
|
|
#include "ps/ConfigDB.h"
|
2005-10-17 01:16:08 +02:00
|
|
|
#include "ps/Globals.h"
|
2015-07-29 03:07:23 +02:00
|
|
|
#include "ps/KeyName.h"
|
2004-07-21 18:51:21 +02:00
|
|
|
|
2010-10-23 04:37:00 +02:00
|
|
|
static bool unified[UNIFIED_LAST - UNIFIED_SHIFT];
|
2005-10-17 01:16:08 +02:00
|
|
|
|
Let players remap hotkeys in-game, fix default hotkeys being qwerty-specific.
- Provide a "Hotkey" screen to let players remap hotkeys in-game using a
convenient setup.
- Make all .cfg hotkeys refer to scancodes (i.e. position on the
keyboard), so that default hotkeys now translate correctly for AZERTY,
QWERTZ and other layouts.
- 'BackSpace' is now an alias for 'Delete', and works for killing units.
This fixes #1917, as macs don't have a proper delete key and would need
to use Fn+Del otherwise. This shifts "timewarp" to Shift+BackSpace.
Functionally, this switches hotkeys to scancodes, as that makes more
sense (they are combinations of key positions, not actual text output).
SDL includes are cleaned and key names are reused.
Fixes #2850, Fixes #2604, Refs #1810, Fixes #1917.
Follows work in 3d7784d2af.
Various diffs tested by: Angen, Stan, Freagarach
Comments by: Nescio
Differential Revision: https://code.wildfiregames.com/D2814
This was SVN commit r24215.
2020-11-19 10:27:26 +01:00
|
|
|
std::unordered_map<int, KeyMapping> g_HotkeyMap;
|
|
|
|
std::unordered_map<std::string, bool> g_HotkeyStatus;
|
2004-07-21 18:51:21 +02:00
|
|
|
|
Let players remap hotkeys in-game, fix default hotkeys being qwerty-specific.
- Provide a "Hotkey" screen to let players remap hotkeys in-game using a
convenient setup.
- Make all .cfg hotkeys refer to scancodes (i.e. position on the
keyboard), so that default hotkeys now translate correctly for AZERTY,
QWERTZ and other layouts.
- 'BackSpace' is now an alias for 'Delete', and works for killing units.
This fixes #1917, as macs don't have a proper delete key and would need
to use Fn+Del otherwise. This shifts "timewarp" to Shift+BackSpace.
Functionally, this switches hotkeys to scancodes, as that makes more
sense (they are combinations of key positions, not actual text output).
SDL includes are cleaned and key names are reused.
Fixes #2850, Fixes #2604, Refs #1810, Fixes #1917.
Follows work in 3d7784d2af.
Various diffs tested by: Angen, Stan, Freagarach
Comments by: Nescio
Differential Revision: https://code.wildfiregames.com/D2814
This was SVN commit r24215.
2020-11-19 10:27:26 +01:00
|
|
|
static_assert(std::is_integral<std::underlying_type<SDL_Scancode>::type>::value, "SDL_Scancode is not an integral enum.");
|
|
|
|
static_assert(SDL_USEREVENT_ == SDL_USEREVENT, "SDL_USEREVENT_ is not the same type as the real SDL_USEREVENT");
|
2004-07-22 18:18:12 +02:00
|
|
|
|
2010-10-23 04:37:00 +02:00
|
|
|
// Look up each key binding in the config file and set the mappings for
|
|
|
|
// all key combinations that trigger it.
|
|
|
|
static void LoadConfigBindings()
|
2004-07-21 18:51:21 +02:00
|
|
|
{
|
2020-12-31 15:27:02 +01:00
|
|
|
for (const std::pair<const CStr, CConfigValueSet>& configPair : g_ConfigDB.GetValuesWithPrefix(CFG_COMMAND, "hotkey."))
|
2004-07-22 18:18:12 +02:00
|
|
|
{
|
2015-07-29 03:07:23 +02:00
|
|
|
std::string hotkeyName = configPair.first.substr(7); // strip the "hotkey." prefix
|
|
|
|
for (const CStr& hotkey : configPair.second)
|
2004-07-22 18:18:12 +02:00
|
|
|
{
|
2016-07-27 14:29:31 +02:00
|
|
|
if (hotkey.LowerCase() == "unused")
|
|
|
|
continue;
|
|
|
|
|
2014-11-17 02:03:59 +01:00
|
|
|
std::vector<SKey> keyCombination;
|
|
|
|
|
|
|
|
// Iterate through multiple-key bindings (e.g. Ctrl+I)
|
|
|
|
boost::char_separator<char> sep("+");
|
|
|
|
typedef boost::tokenizer<boost::char_separator<char> > tokenizer;
|
|
|
|
tokenizer tok(hotkey, sep);
|
|
|
|
for (tokenizer::iterator it = tok.begin(); it != tok.end(); ++it)
|
2004-07-21 18:51:21 +02:00
|
|
|
{
|
2014-11-17 02:03:59 +01:00
|
|
|
// Attempt decode as key name
|
Let players remap hotkeys in-game, fix default hotkeys being qwerty-specific.
- Provide a "Hotkey" screen to let players remap hotkeys in-game using a
convenient setup.
- Make all .cfg hotkeys refer to scancodes (i.e. position on the
keyboard), so that default hotkeys now translate correctly for AZERTY,
QWERTZ and other layouts.
- 'BackSpace' is now an alias for 'Delete', and works for killing units.
This fixes #1917, as macs don't have a proper delete key and would need
to use Fn+Del otherwise. This shifts "timewarp" to Shift+BackSpace.
Functionally, this switches hotkeys to scancodes, as that makes more
sense (they are combinations of key positions, not actual text output).
SDL includes are cleaned and key names are reused.
Fixes #2850, Fixes #2604, Refs #1810, Fixes #1917.
Follows work in 3d7784d2af.
Various diffs tested by: Angen, Stan, Freagarach
Comments by: Nescio
Differential Revision: https://code.wildfiregames.com/D2814
This was SVN commit r24215.
2020-11-19 10:27:26 +01:00
|
|
|
SDL_Scancode scancode = FindScancode(it->c_str());
|
|
|
|
if (!scancode)
|
2004-07-22 18:18:12 +02:00
|
|
|
{
|
2015-01-22 21:36:24 +01:00
|
|
|
LOGWARNING("Hotkey mapping used invalid key '%s'", hotkey.c_str());
|
2014-11-17 02:03:59 +01:00
|
|
|
continue;
|
2004-07-22 18:18:12 +02:00
|
|
|
}
|
2004-07-21 18:51:21 +02:00
|
|
|
|
Let players remap hotkeys in-game, fix default hotkeys being qwerty-specific.
- Provide a "Hotkey" screen to let players remap hotkeys in-game using a
convenient setup.
- Make all .cfg hotkeys refer to scancodes (i.e. position on the
keyboard), so that default hotkeys now translate correctly for AZERTY,
QWERTZ and other layouts.
- 'BackSpace' is now an alias for 'Delete', and works for killing units.
This fixes #1917, as macs don't have a proper delete key and would need
to use Fn+Del otherwise. This shifts "timewarp" to Shift+BackSpace.
Functionally, this switches hotkeys to scancodes, as that makes more
sense (they are combinations of key positions, not actual text output).
SDL includes are cleaned and key names are reused.
Fixes #2850, Fixes #2604, Refs #1810, Fixes #1917.
Follows work in 3d7784d2af.
Various diffs tested by: Angen, Stan, Freagarach
Comments by: Nescio
Differential Revision: https://code.wildfiregames.com/D2814
This was SVN commit r24215.
2020-11-19 10:27:26 +01:00
|
|
|
SKey key = { scancode, false };
|
2014-11-17 02:03:59 +01:00
|
|
|
keyCombination.push_back(key);
|
|
|
|
}
|
2004-07-21 18:51:21 +02:00
|
|
|
|
2014-11-17 02:03:59 +01:00
|
|
|
std::vector<SKey>::iterator itKey, itKey2;
|
|
|
|
for (itKey = keyCombination.begin(); itKey != keyCombination.end(); ++itKey)
|
|
|
|
{
|
|
|
|
SHotkeyMapping bindCode;
|
2010-10-23 04:37:00 +02:00
|
|
|
|
2014-11-17 02:03:59 +01:00
|
|
|
bindCode.name = hotkeyName;
|
|
|
|
bindCode.negated = itKey->negated;
|
2010-10-23 04:37:00 +02:00
|
|
|
|
2014-11-17 02:03:59 +01:00
|
|
|
for (itKey2 = keyCombination.begin(); itKey2 != keyCombination.end(); ++itKey2)
|
|
|
|
if (itKey != itKey2) // Push any auxiliary keys
|
|
|
|
bindCode.requires.push_back(*itKey2);
|
2004-08-03 01:14:54 +02:00
|
|
|
|
2014-11-17 02:03:59 +01:00
|
|
|
g_HotkeyMap[itKey->code].push_back(bindCode);
|
2004-07-21 18:51:21 +02:00
|
|
|
}
|
|
|
|
}
|
2004-07-22 18:18:12 +02:00
|
|
|
}
|
2004-07-21 18:51:21 +02:00
|
|
|
}
|
2010-10-23 04:37:00 +02:00
|
|
|
|
2007-05-02 14:07:08 +02:00
|
|
|
void LoadHotkeys()
|
2004-07-22 18:18:12 +02:00
|
|
|
{
|
2010-10-23 04:37:00 +02:00
|
|
|
LoadConfigBindings();
|
|
|
|
|
2004-11-11 08:09:32 +01:00
|
|
|
// Set up the state of the hotkeys given no key is down.
|
|
|
|
// i.e. find those hotkeys triggered by all negations.
|
|
|
|
|
2020-12-31 15:27:02 +01:00
|
|
|
for (const std::pair<const int, KeyMapping>& p : g_HotkeyMap)
|
2015-07-29 03:07:23 +02:00
|
|
|
for (const SHotkeyMapping& hotkey : p.second)
|
2004-11-11 08:09:32 +01:00
|
|
|
{
|
2015-07-29 03:07:23 +02:00
|
|
|
if (!hotkey.negated)
|
2004-11-11 08:09:32 +01:00
|
|
|
continue;
|
|
|
|
|
2010-10-23 04:37:00 +02:00
|
|
|
bool allNegated = true;
|
2004-11-11 08:09:32 +01:00
|
|
|
|
2015-07-29 03:07:23 +02:00
|
|
|
for (const SKey& k : hotkey.requires)
|
|
|
|
if (!k.negated)
|
2004-11-11 08:09:32 +01:00
|
|
|
allNegated = false;
|
2016-11-23 15:09:58 +01:00
|
|
|
|
2015-07-29 03:07:23 +02:00
|
|
|
if (allNegated)
|
|
|
|
g_HotkeyStatus[hotkey.name] = true;
|
2004-11-11 08:09:32 +01:00
|
|
|
}
|
2004-07-22 18:18:12 +02:00
|
|
|
}
|
|
|
|
|
2014-09-15 03:27:06 +02:00
|
|
|
void UnloadHotkeys()
|
|
|
|
{
|
|
|
|
g_HotkeyMap.clear();
|
|
|
|
g_HotkeyStatus.clear();
|
|
|
|
}
|
|
|
|
|
2014-08-04 18:48:54 +02:00
|
|
|
bool isNegated(const SKey& key)
|
|
|
|
{
|
|
|
|
// Normal keycodes are below EXTRA_KEYS_BASE
|
|
|
|
if ((int)key.code < EXTRA_KEYS_BASE && g_keys[key.code] == key.negated)
|
|
|
|
return false;
|
|
|
|
// Mouse 'keycodes' are after the modifier keys
|
2017-05-19 20:01:22 +02:00
|
|
|
else if ((int)key.code < MOUSE_LAST && (int)key.code > MOUSE_BASE && g_mouse_buttons[key.code - MOUSE_BASE] == key.negated)
|
2014-08-04 18:48:54 +02:00
|
|
|
return false;
|
|
|
|
// Modifier keycodes are between the normal keys and the mouse 'keys'
|
Let players remap hotkeys in-game, fix default hotkeys being qwerty-specific.
- Provide a "Hotkey" screen to let players remap hotkeys in-game using a
convenient setup.
- Make all .cfg hotkeys refer to scancodes (i.e. position on the
keyboard), so that default hotkeys now translate correctly for AZERTY,
QWERTZ and other layouts.
- 'BackSpace' is now an alias for 'Delete', and works for killing units.
This fixes #1917, as macs don't have a proper delete key and would need
to use Fn+Del otherwise. This shifts "timewarp" to Shift+BackSpace.
Functionally, this switches hotkeys to scancodes, as that makes more
sense (they are combinations of key positions, not actual text output).
SDL includes are cleaned and key names are reused.
Fixes #2850, Fixes #2604, Refs #1810, Fixes #1917.
Follows work in 3d7784d2af.
Various diffs tested by: Angen, Stan, Freagarach
Comments by: Nescio
Differential Revision: https://code.wildfiregames.com/D2814
This was SVN commit r24215.
2020-11-19 10:27:26 +01:00
|
|
|
else if ((int)key.code < UNIFIED_LAST && (int)key.code > SDL_NUM_SCANCODES && unified[key.code - UNIFIED_SHIFT] == key.negated)
|
2014-08-04 18:48:54 +02:00
|
|
|
return false;
|
|
|
|
else
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2019-09-15 14:16:28 +02:00
|
|
|
InReaction HotkeyStateChange(const SDL_Event_* ev)
|
|
|
|
{
|
2020-05-26 23:47:03 +02:00
|
|
|
if (ev->ev.type == SDL_HOTKEYPRESS)
|
2019-09-15 14:16:28 +02:00
|
|
|
g_HotkeyStatus[static_cast<const char*>(ev->ev.user.data1)] = true;
|
|
|
|
else if (ev->ev.type == SDL_HOTKEYUP)
|
|
|
|
g_HotkeyStatus[static_cast<const char*>(ev->ev.user.data1)] = false;
|
|
|
|
return IN_PASS;
|
|
|
|
}
|
|
|
|
|
2015-07-29 03:07:23 +02:00
|
|
|
InReaction HotkeyInputHandler(const SDL_Event_* ev)
|
2004-07-21 18:51:21 +02:00
|
|
|
{
|
Let players remap hotkeys in-game, fix default hotkeys being qwerty-specific.
- Provide a "Hotkey" screen to let players remap hotkeys in-game using a
convenient setup.
- Make all .cfg hotkeys refer to scancodes (i.e. position on the
keyboard), so that default hotkeys now translate correctly for AZERTY,
QWERTZ and other layouts.
- 'BackSpace' is now an alias for 'Delete', and works for killing units.
This fixes #1917, as macs don't have a proper delete key and would need
to use Fn+Del otherwise. This shifts "timewarp" to Shift+BackSpace.
Functionally, this switches hotkeys to scancodes, as that makes more
sense (they are combinations of key positions, not actual text output).
SDL includes are cleaned and key names are reused.
Fixes #2850, Fixes #2604, Refs #1810, Fixes #1917.
Follows work in 3d7784d2af.
Various diffs tested by: Angen, Stan, Freagarach
Comments by: Nescio
Differential Revision: https://code.wildfiregames.com/D2814
This was SVN commit r24215.
2020-11-19 10:27:26 +01:00
|
|
|
int scancode = SDL_SCANCODE_UNKNOWN;
|
2004-07-21 18:51:21 +02:00
|
|
|
|
2015-07-29 03:07:23 +02:00
|
|
|
switch(ev->ev.type)
|
2004-07-21 18:51:21 +02:00
|
|
|
{
|
|
|
|
case SDL_KEYDOWN:
|
|
|
|
case SDL_KEYUP:
|
Let players remap hotkeys in-game, fix default hotkeys being qwerty-specific.
- Provide a "Hotkey" screen to let players remap hotkeys in-game using a
convenient setup.
- Make all .cfg hotkeys refer to scancodes (i.e. position on the
keyboard), so that default hotkeys now translate correctly for AZERTY,
QWERTZ and other layouts.
- 'BackSpace' is now an alias for 'Delete', and works for killing units.
This fixes #1917, as macs don't have a proper delete key and would need
to use Fn+Del otherwise. This shifts "timewarp" to Shift+BackSpace.
Functionally, this switches hotkeys to scancodes, as that makes more
sense (they are combinations of key positions, not actual text output).
SDL includes are cleaned and key names are reused.
Fixes #2850, Fixes #2604, Refs #1810, Fixes #1917.
Follows work in 3d7784d2af.
Various diffs tested by: Angen, Stan, Freagarach
Comments by: Nescio
Differential Revision: https://code.wildfiregames.com/D2814
This was SVN commit r24215.
2020-11-19 10:27:26 +01:00
|
|
|
scancode = ev->ev.key.keysym.scancode;
|
2004-07-21 18:51:21 +02:00
|
|
|
break;
|
2012-02-06 23:47:35 +01:00
|
|
|
|
2004-07-21 18:51:21 +02:00
|
|
|
case SDL_MOUSEBUTTONDOWN:
|
|
|
|
case SDL_MOUSEBUTTONUP:
|
2014-09-20 14:12:35 +02:00
|
|
|
// Mousewheel events are no longer buttons, but we want to maintain the order
|
|
|
|
// expected by g_mouse_buttons for compatibility
|
|
|
|
if (ev->ev.button.button >= SDL_BUTTON_X1)
|
Let players remap hotkeys in-game, fix default hotkeys being qwerty-specific.
- Provide a "Hotkey" screen to let players remap hotkeys in-game using a
convenient setup.
- Make all .cfg hotkeys refer to scancodes (i.e. position on the
keyboard), so that default hotkeys now translate correctly for AZERTY,
QWERTZ and other layouts.
- 'BackSpace' is now an alias for 'Delete', and works for killing units.
This fixes #1917, as macs don't have a proper delete key and would need
to use Fn+Del otherwise. This shifts "timewarp" to Shift+BackSpace.
Functionally, this switches hotkeys to scancodes, as that makes more
sense (they are combinations of key positions, not actual text output).
SDL includes are cleaned and key names are reused.
Fixes #2850, Fixes #2604, Refs #1810, Fixes #1917.
Follows work in 3d7784d2af.
Various diffs tested by: Angen, Stan, Freagarach
Comments by: Nescio
Differential Revision: https://code.wildfiregames.com/D2814
This was SVN commit r24215.
2020-11-19 10:27:26 +01:00
|
|
|
scancode = MOUSE_BASE + (int)ev->ev.button.button + 2;
|
2014-09-20 14:12:35 +02:00
|
|
|
else
|
Let players remap hotkeys in-game, fix default hotkeys being qwerty-specific.
- Provide a "Hotkey" screen to let players remap hotkeys in-game using a
convenient setup.
- Make all .cfg hotkeys refer to scancodes (i.e. position on the
keyboard), so that default hotkeys now translate correctly for AZERTY,
QWERTZ and other layouts.
- 'BackSpace' is now an alias for 'Delete', and works for killing units.
This fixes #1917, as macs don't have a proper delete key and would need
to use Fn+Del otherwise. This shifts "timewarp" to Shift+BackSpace.
Functionally, this switches hotkeys to scancodes, as that makes more
sense (they are combinations of key positions, not actual text output).
SDL includes are cleaned and key names are reused.
Fixes #2850, Fixes #2604, Refs #1810, Fixes #1917.
Follows work in 3d7784d2af.
Various diffs tested by: Angen, Stan, Freagarach
Comments by: Nescio
Differential Revision: https://code.wildfiregames.com/D2814
This was SVN commit r24215.
2020-11-19 10:27:26 +01:00
|
|
|
scancode = MOUSE_BASE + (int)ev->ev.button.button;
|
2014-08-04 03:06:36 +02:00
|
|
|
break;
|
2014-09-20 14:12:35 +02:00
|
|
|
|
2012-02-06 23:47:35 +01:00
|
|
|
case SDL_MOUSEWHEEL:
|
2013-04-05 04:39:30 +02:00
|
|
|
if (ev->ev.wheel.y > 0)
|
2012-02-06 23:47:35 +01:00
|
|
|
{
|
Let players remap hotkeys in-game, fix default hotkeys being qwerty-specific.
- Provide a "Hotkey" screen to let players remap hotkeys in-game using a
convenient setup.
- Make all .cfg hotkeys refer to scancodes (i.e. position on the
keyboard), so that default hotkeys now translate correctly for AZERTY,
QWERTZ and other layouts.
- 'BackSpace' is now an alias for 'Delete', and works for killing units.
This fixes #1917, as macs don't have a proper delete key and would need
to use Fn+Del otherwise. This shifts "timewarp" to Shift+BackSpace.
Functionally, this switches hotkeys to scancodes, as that makes more
sense (they are combinations of key positions, not actual text output).
SDL includes are cleaned and key names are reused.
Fixes #2850, Fixes #2604, Refs #1810, Fixes #1917.
Follows work in 3d7784d2af.
Various diffs tested by: Angen, Stan, Freagarach
Comments by: Nescio
Differential Revision: https://code.wildfiregames.com/D2814
This was SVN commit r24215.
2020-11-19 10:27:26 +01:00
|
|
|
scancode = MOUSE_WHEELUP;
|
2012-02-06 23:47:35 +01:00
|
|
|
break;
|
|
|
|
}
|
2013-04-05 04:39:30 +02:00
|
|
|
else if (ev->ev.wheel.y < 0)
|
2012-02-06 23:47:35 +01:00
|
|
|
{
|
Let players remap hotkeys in-game, fix default hotkeys being qwerty-specific.
- Provide a "Hotkey" screen to let players remap hotkeys in-game using a
convenient setup.
- Make all .cfg hotkeys refer to scancodes (i.e. position on the
keyboard), so that default hotkeys now translate correctly for AZERTY,
QWERTZ and other layouts.
- 'BackSpace' is now an alias for 'Delete', and works for killing units.
This fixes #1917, as macs don't have a proper delete key and would need
to use Fn+Del otherwise. This shifts "timewarp" to Shift+BackSpace.
Functionally, this switches hotkeys to scancodes, as that makes more
sense (they are combinations of key positions, not actual text output).
SDL includes are cleaned and key names are reused.
Fixes #2850, Fixes #2604, Refs #1810, Fixes #1917.
Follows work in 3d7784d2af.
Various diffs tested by: Angen, Stan, Freagarach
Comments by: Nescio
Differential Revision: https://code.wildfiregames.com/D2814
This was SVN commit r24215.
2020-11-19 10:27:26 +01:00
|
|
|
scancode = MOUSE_WHEELDOWN;
|
2012-02-06 23:47:35 +01:00
|
|
|
break;
|
|
|
|
}
|
2014-09-20 14:12:35 +02:00
|
|
|
else if (ev->ev.wheel.x > 0)
|
|
|
|
{
|
Let players remap hotkeys in-game, fix default hotkeys being qwerty-specific.
- Provide a "Hotkey" screen to let players remap hotkeys in-game using a
convenient setup.
- Make all .cfg hotkeys refer to scancodes (i.e. position on the
keyboard), so that default hotkeys now translate correctly for AZERTY,
QWERTZ and other layouts.
- 'BackSpace' is now an alias for 'Delete', and works for killing units.
This fixes #1917, as macs don't have a proper delete key and would need
to use Fn+Del otherwise. This shifts "timewarp" to Shift+BackSpace.
Functionally, this switches hotkeys to scancodes, as that makes more
sense (they are combinations of key positions, not actual text output).
SDL includes are cleaned and key names are reused.
Fixes #2850, Fixes #2604, Refs #1810, Fixes #1917.
Follows work in 3d7784d2af.
Various diffs tested by: Angen, Stan, Freagarach
Comments by: Nescio
Differential Revision: https://code.wildfiregames.com/D2814
This was SVN commit r24215.
2020-11-19 10:27:26 +01:00
|
|
|
scancode = MOUSE_X2;
|
2014-09-20 14:12:35 +02:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
else if (ev->ev.wheel.x < 0)
|
|
|
|
{
|
Let players remap hotkeys in-game, fix default hotkeys being qwerty-specific.
- Provide a "Hotkey" screen to let players remap hotkeys in-game using a
convenient setup.
- Make all .cfg hotkeys refer to scancodes (i.e. position on the
keyboard), so that default hotkeys now translate correctly for AZERTY,
QWERTZ and other layouts.
- 'BackSpace' is now an alias for 'Delete', and works for killing units.
This fixes #1917, as macs don't have a proper delete key and would need
to use Fn+Del otherwise. This shifts "timewarp" to Shift+BackSpace.
Functionally, this switches hotkeys to scancodes, as that makes more
sense (they are combinations of key positions, not actual text output).
SDL includes are cleaned and key names are reused.
Fixes #2850, Fixes #2604, Refs #1810, Fixes #1917.
Follows work in 3d7784d2af.
Various diffs tested by: Angen, Stan, Freagarach
Comments by: Nescio
Differential Revision: https://code.wildfiregames.com/D2814
This was SVN commit r24215.
2020-11-19 10:27:26 +01:00
|
|
|
scancode = MOUSE_X1;
|
2014-09-20 14:12:35 +02:00
|
|
|
break;
|
|
|
|
}
|
2012-02-06 23:47:35 +01:00
|
|
|
return IN_PASS;
|
|
|
|
|
Improve correctness of hotkeys at low framerates.
SDL queues up all the input events received in a frame. When the hotkey
system saw a key up/down event, it immediately updated its
HotkeyIsPressed state and then pushed a hotkey event onto the end of the
queue.
If the initial queue was e.g. [key-down shift, key-press Z, key-up
shift], the hotkey event triggered by Z would be processed after the
key-up shift had updated the HotkeyIsPressed state, so the handler of
the Z hotkey would not think the shift hotkey was pressed.
If the initial queue was e.g. [key-press Z, mouse-click], the hotkey
triggered by Z would be processed after the mouse-click event, so it
could apply to the wrong building selection.
Fix by pushing the hotkey events onto a special queue that gets
processed before any subsequent SDL input events.
Also update the HotkeyIsPressed status when the HOTKEYDOWN/HOTKEYUP
events are processed, not when they are generated, to guarantee they are
consistent with the DOWN/UP events.
Fixes #1869.
This was SVN commit r14057.
2013-10-30 02:38:32 +01:00
|
|
|
|
2004-07-21 18:51:21 +02:00
|
|
|
default:
|
2007-05-26 20:38:38 +02:00
|
|
|
return IN_PASS;
|
2004-07-21 18:51:21 +02:00
|
|
|
}
|
|
|
|
|
2004-08-03 01:14:54 +02:00
|
|
|
// Somewhat hackish:
|
|
|
|
// Create phantom 'unified-modifier' events when left- or right- modifier keys are pressed
|
|
|
|
// Just send them to this handler; don't let the imaginary event codes leak back to real SDL.
|
|
|
|
|
2006-08-26 23:52:18 +02:00
|
|
|
SDL_Event_ phantom;
|
2015-07-29 03:07:23 +02:00
|
|
|
phantom.ev.type = ((ev->ev.type == SDL_KEYDOWN) || (ev->ev.type == SDL_MOUSEBUTTONDOWN)) ? SDL_KEYDOWN : SDL_KEYUP;
|
2020-05-26 23:47:03 +02:00
|
|
|
if (phantom.ev.type == SDL_KEYDOWN)
|
|
|
|
phantom.ev.key.repeat = ev->ev.type == SDL_KEYDOWN ? ev->ev.key.repeat : 0;
|
|
|
|
|
Let players remap hotkeys in-game, fix default hotkeys being qwerty-specific.
- Provide a "Hotkey" screen to let players remap hotkeys in-game using a
convenient setup.
- Make all .cfg hotkeys refer to scancodes (i.e. position on the
keyboard), so that default hotkeys now translate correctly for AZERTY,
QWERTZ and other layouts.
- 'BackSpace' is now an alias for 'Delete', and works for killing units.
This fixes #1917, as macs don't have a proper delete key and would need
to use Fn+Del otherwise. This shifts "timewarp" to Shift+BackSpace.
Functionally, this switches hotkeys to scancodes, as that makes more
sense (they are combinations of key positions, not actual text output).
SDL includes are cleaned and key names are reused.
Fixes #2850, Fixes #2604, Refs #1810, Fixes #1917.
Follows work in 3d7784d2af.
Various diffs tested by: Angen, Stan, Freagarach
Comments by: Nescio
Differential Revision: https://code.wildfiregames.com/D2814
This was SVN commit r24215.
2020-11-19 10:27:26 +01:00
|
|
|
if (scancode == SDL_SCANCODE_LSHIFT || scancode == SDL_SCANCODE_RSHIFT)
|
2004-08-03 01:14:54 +02:00
|
|
|
{
|
Let players remap hotkeys in-game, fix default hotkeys being qwerty-specific.
- Provide a "Hotkey" screen to let players remap hotkeys in-game using a
convenient setup.
- Make all .cfg hotkeys refer to scancodes (i.e. position on the
keyboard), so that default hotkeys now translate correctly for AZERTY,
QWERTZ and other layouts.
- 'BackSpace' is now an alias for 'Delete', and works for killing units.
This fixes #1917, as macs don't have a proper delete key and would need
to use Fn+Del otherwise. This shifts "timewarp" to Shift+BackSpace.
Functionally, this switches hotkeys to scancodes, as that makes more
sense (they are combinations of key positions, not actual text output).
SDL includes are cleaned and key names are reused.
Fixes #2850, Fixes #2604, Refs #1810, Fixes #1917.
Follows work in 3d7784d2af.
Various diffs tested by: Angen, Stan, Freagarach
Comments by: Nescio
Differential Revision: https://code.wildfiregames.com/D2814
This was SVN commit r24215.
2020-11-19 10:27:26 +01:00
|
|
|
phantom.ev.key.keysym.scancode = static_cast<SDL_Scancode>(UNIFIED_SHIFT);
|
2015-07-29 03:07:23 +02:00
|
|
|
unified[0] = (phantom.ev.type == SDL_KEYDOWN);
|
|
|
|
HotkeyInputHandler(&phantom);
|
2004-08-03 01:14:54 +02:00
|
|
|
}
|
Let players remap hotkeys in-game, fix default hotkeys being qwerty-specific.
- Provide a "Hotkey" screen to let players remap hotkeys in-game using a
convenient setup.
- Make all .cfg hotkeys refer to scancodes (i.e. position on the
keyboard), so that default hotkeys now translate correctly for AZERTY,
QWERTZ and other layouts.
- 'BackSpace' is now an alias for 'Delete', and works for killing units.
This fixes #1917, as macs don't have a proper delete key and would need
to use Fn+Del otherwise. This shifts "timewarp" to Shift+BackSpace.
Functionally, this switches hotkeys to scancodes, as that makes more
sense (they are combinations of key positions, not actual text output).
SDL includes are cleaned and key names are reused.
Fixes #2850, Fixes #2604, Refs #1810, Fixes #1917.
Follows work in 3d7784d2af.
Various diffs tested by: Angen, Stan, Freagarach
Comments by: Nescio
Differential Revision: https://code.wildfiregames.com/D2814
This was SVN commit r24215.
2020-11-19 10:27:26 +01:00
|
|
|
else if (scancode == SDL_SCANCODE_LCTRL || scancode == SDL_SCANCODE_RCTRL)
|
2004-08-03 01:14:54 +02:00
|
|
|
{
|
Let players remap hotkeys in-game, fix default hotkeys being qwerty-specific.
- Provide a "Hotkey" screen to let players remap hotkeys in-game using a
convenient setup.
- Make all .cfg hotkeys refer to scancodes (i.e. position on the
keyboard), so that default hotkeys now translate correctly for AZERTY,
QWERTZ and other layouts.
- 'BackSpace' is now an alias for 'Delete', and works for killing units.
This fixes #1917, as macs don't have a proper delete key and would need
to use Fn+Del otherwise. This shifts "timewarp" to Shift+BackSpace.
Functionally, this switches hotkeys to scancodes, as that makes more
sense (they are combinations of key positions, not actual text output).
SDL includes are cleaned and key names are reused.
Fixes #2850, Fixes #2604, Refs #1810, Fixes #1917.
Follows work in 3d7784d2af.
Various diffs tested by: Angen, Stan, Freagarach
Comments by: Nescio
Differential Revision: https://code.wildfiregames.com/D2814
This was SVN commit r24215.
2020-11-19 10:27:26 +01:00
|
|
|
phantom.ev.key.keysym.scancode = static_cast<SDL_Scancode>(UNIFIED_CTRL);
|
2015-07-29 03:07:23 +02:00
|
|
|
unified[1] = (phantom.ev.type == SDL_KEYDOWN);
|
|
|
|
HotkeyInputHandler(&phantom);
|
2004-08-03 01:14:54 +02:00
|
|
|
}
|
Let players remap hotkeys in-game, fix default hotkeys being qwerty-specific.
- Provide a "Hotkey" screen to let players remap hotkeys in-game using a
convenient setup.
- Make all .cfg hotkeys refer to scancodes (i.e. position on the
keyboard), so that default hotkeys now translate correctly for AZERTY,
QWERTZ and other layouts.
- 'BackSpace' is now an alias for 'Delete', and works for killing units.
This fixes #1917, as macs don't have a proper delete key and would need
to use Fn+Del otherwise. This shifts "timewarp" to Shift+BackSpace.
Functionally, this switches hotkeys to scancodes, as that makes more
sense (they are combinations of key positions, not actual text output).
SDL includes are cleaned and key names are reused.
Fixes #2850, Fixes #2604, Refs #1810, Fixes #1917.
Follows work in 3d7784d2af.
Various diffs tested by: Angen, Stan, Freagarach
Comments by: Nescio
Differential Revision: https://code.wildfiregames.com/D2814
This was SVN commit r24215.
2020-11-19 10:27:26 +01:00
|
|
|
else if (scancode == SDL_SCANCODE_LALT || scancode == SDL_SCANCODE_RALT)
|
2004-08-03 01:14:54 +02:00
|
|
|
{
|
Let players remap hotkeys in-game, fix default hotkeys being qwerty-specific.
- Provide a "Hotkey" screen to let players remap hotkeys in-game using a
convenient setup.
- Make all .cfg hotkeys refer to scancodes (i.e. position on the
keyboard), so that default hotkeys now translate correctly for AZERTY,
QWERTZ and other layouts.
- 'BackSpace' is now an alias for 'Delete', and works for killing units.
This fixes #1917, as macs don't have a proper delete key and would need
to use Fn+Del otherwise. This shifts "timewarp" to Shift+BackSpace.
Functionally, this switches hotkeys to scancodes, as that makes more
sense (they are combinations of key positions, not actual text output).
SDL includes are cleaned and key names are reused.
Fixes #2850, Fixes #2604, Refs #1810, Fixes #1917.
Follows work in 3d7784d2af.
Various diffs tested by: Angen, Stan, Freagarach
Comments by: Nescio
Differential Revision: https://code.wildfiregames.com/D2814
This was SVN commit r24215.
2020-11-19 10:27:26 +01:00
|
|
|
phantom.ev.key.keysym.scancode = static_cast<SDL_Scancode>(UNIFIED_ALT);
|
2015-07-29 03:07:23 +02:00
|
|
|
unified[2] = (phantom.ev.type == SDL_KEYDOWN);
|
|
|
|
HotkeyInputHandler(&phantom);
|
2004-08-03 01:14:54 +02:00
|
|
|
}
|
Let players remap hotkeys in-game, fix default hotkeys being qwerty-specific.
- Provide a "Hotkey" screen to let players remap hotkeys in-game using a
convenient setup.
- Make all .cfg hotkeys refer to scancodes (i.e. position on the
keyboard), so that default hotkeys now translate correctly for AZERTY,
QWERTZ and other layouts.
- 'BackSpace' is now an alias for 'Delete', and works for killing units.
This fixes #1917, as macs don't have a proper delete key and would need
to use Fn+Del otherwise. This shifts "timewarp" to Shift+BackSpace.
Functionally, this switches hotkeys to scancodes, as that makes more
sense (they are combinations of key positions, not actual text output).
SDL includes are cleaned and key names are reused.
Fixes #2850, Fixes #2604, Refs #1810, Fixes #1917.
Follows work in 3d7784d2af.
Various diffs tested by: Angen, Stan, Freagarach
Comments by: Nescio
Differential Revision: https://code.wildfiregames.com/D2814
This was SVN commit r24215.
2020-11-19 10:27:26 +01:00
|
|
|
else if (scancode == SDL_SCANCODE_LGUI || scancode == SDL_SCANCODE_RGUI)
|
2004-08-03 01:14:54 +02:00
|
|
|
{
|
Let players remap hotkeys in-game, fix default hotkeys being qwerty-specific.
- Provide a "Hotkey" screen to let players remap hotkeys in-game using a
convenient setup.
- Make all .cfg hotkeys refer to scancodes (i.e. position on the
keyboard), so that default hotkeys now translate correctly for AZERTY,
QWERTZ and other layouts.
- 'BackSpace' is now an alias for 'Delete', and works for killing units.
This fixes #1917, as macs don't have a proper delete key and would need
to use Fn+Del otherwise. This shifts "timewarp" to Shift+BackSpace.
Functionally, this switches hotkeys to scancodes, as that makes more
sense (they are combinations of key positions, not actual text output).
SDL includes are cleaned and key names are reused.
Fixes #2850, Fixes #2604, Refs #1810, Fixes #1917.
Follows work in 3d7784d2af.
Various diffs tested by: Angen, Stan, Freagarach
Comments by: Nescio
Differential Revision: https://code.wildfiregames.com/D2814
This was SVN commit r24215.
2020-11-19 10:27:26 +01:00
|
|
|
phantom.ev.key.keysym.scancode = static_cast<SDL_Scancode>(UNIFIED_SUPER);
|
2015-07-29 03:07:23 +02:00
|
|
|
unified[3] = (phantom.ev.type == SDL_KEYDOWN);
|
|
|
|
HotkeyInputHandler(&phantom);
|
2004-08-03 01:14:54 +02:00
|
|
|
}
|
|
|
|
|
2010-10-23 04:37:00 +02:00
|
|
|
// Check whether we have any hotkeys registered for this particular keycode
|
Let players remap hotkeys in-game, fix default hotkeys being qwerty-specific.
- Provide a "Hotkey" screen to let players remap hotkeys in-game using a
convenient setup.
- Make all .cfg hotkeys refer to scancodes (i.e. position on the
keyboard), so that default hotkeys now translate correctly for AZERTY,
QWERTZ and other layouts.
- 'BackSpace' is now an alias for 'Delete', and works for killing units.
This fixes #1917, as macs don't have a proper delete key and would need
to use Fn+Del otherwise. This shifts "timewarp" to Shift+BackSpace.
Functionally, this switches hotkeys to scancodes, as that makes more
sense (they are combinations of key positions, not actual text output).
SDL includes are cleaned and key names are reused.
Fixes #2850, Fixes #2604, Refs #1810, Fixes #1917.
Follows work in 3d7784d2af.
Various diffs tested by: Angen, Stan, Freagarach
Comments by: Nescio
Differential Revision: https://code.wildfiregames.com/D2814
This was SVN commit r24215.
2020-11-19 10:27:26 +01:00
|
|
|
if (g_HotkeyMap.find(scancode) == g_HotkeyMap.end())
|
2015-07-29 03:07:23 +02:00
|
|
|
return (IN_PASS);
|
2010-10-23 04:37:00 +02:00
|
|
|
|
2011-02-20 21:50:26 +01:00
|
|
|
// Inhibit the dispatch of hotkey events caused by real keys (not fake mouse button
|
|
|
|
// events) while the console is up.
|
2004-08-03 01:14:54 +02:00
|
|
|
|
2010-10-23 04:37:00 +02:00
|
|
|
bool consoleCapture = false;
|
2004-07-22 18:18:12 +02:00
|
|
|
|
Let players remap hotkeys in-game, fix default hotkeys being qwerty-specific.
- Provide a "Hotkey" screen to let players remap hotkeys in-game using a
convenient setup.
- Make all .cfg hotkeys refer to scancodes (i.e. position on the
keyboard), so that default hotkeys now translate correctly for AZERTY,
QWERTZ and other layouts.
- 'BackSpace' is now an alias for 'Delete', and works for killing units.
This fixes #1917, as macs don't have a proper delete key and would need
to use Fn+Del otherwise. This shifts "timewarp" to Shift+BackSpace.
Functionally, this switches hotkeys to scancodes, as that makes more
sense (they are combinations of key positions, not actual text output).
SDL includes are cleaned and key names are reused.
Fixes #2850, Fixes #2604, Refs #1810, Fixes #1917.
Follows work in 3d7784d2af.
Various diffs tested by: Angen, Stan, Freagarach
Comments by: Nescio
Differential Revision: https://code.wildfiregames.com/D2814
This was SVN commit r24215.
2020-11-19 10:27:26 +01:00
|
|
|
if (g_Console && g_Console->IsActive() && scancode < SDL_NUM_SCANCODES)
|
2004-08-03 01:14:54 +02:00
|
|
|
consoleCapture = true;
|
2004-07-22 18:18:12 +02:00
|
|
|
|
2004-07-23 12:56:52 +02:00
|
|
|
// Here's an interesting bit:
|
|
|
|
// If you have an event bound to, say, 'F', and another to, say, 'Ctrl+F', pressing
|
2004-08-03 01:14:54 +02:00
|
|
|
// 'F' while control is down would normally fire off both.
|
2004-07-23 12:56:52 +02:00
|
|
|
|
|
|
|
// To avoid this, set the modifier keys for /all/ events this key would trigger
|
|
|
|
// (Ctrl, for example, is both group-save and bookmark-save)
|
2020-05-26 23:47:03 +02:00
|
|
|
// but only send a HotkeyPress/HotkeyDown event for the event with bindings most precisely
|
2004-08-03 01:14:54 +02:00
|
|
|
// matching the conditions (i.e. the event with the highest number of auxiliary
|
2004-07-23 12:56:52 +02:00
|
|
|
// keys, providing they're all down)
|
|
|
|
|
2013-04-05 04:39:30 +02:00
|
|
|
bool typeKeyDown = ( ev->ev.type == SDL_KEYDOWN ) || ( ev->ev.type == SDL_MOUSEBUTTONDOWN ) || (ev->ev.type == SDL_MOUSEWHEEL);
|
2014-08-04 18:48:54 +02:00
|
|
|
|
2016-11-23 14:02:58 +01:00
|
|
|
// -- KEYDOWN SECTION --
|
2004-11-11 08:09:32 +01:00
|
|
|
|
2010-11-07 21:42:52 +01:00
|
|
|
std::vector<const char*> closestMapNames;
|
2004-11-11 08:09:32 +01:00
|
|
|
size_t closestMapMatch = 0;
|
|
|
|
|
Let players remap hotkeys in-game, fix default hotkeys being qwerty-specific.
- Provide a "Hotkey" screen to let players remap hotkeys in-game using a
convenient setup.
- Make all .cfg hotkeys refer to scancodes (i.e. position on the
keyboard), so that default hotkeys now translate correctly for AZERTY,
QWERTZ and other layouts.
- 'BackSpace' is now an alias for 'Delete', and works for killing units.
This fixes #1917, as macs don't have a proper delete key and would need
to use Fn+Del otherwise. This shifts "timewarp" to Shift+BackSpace.
Functionally, this switches hotkeys to scancodes, as that makes more
sense (they are combinations of key positions, not actual text output).
SDL includes are cleaned and key names are reused.
Fixes #2850, Fixes #2604, Refs #1810, Fixes #1917.
Follows work in 3d7784d2af.
Various diffs tested by: Angen, Stan, Freagarach
Comments by: Nescio
Differential Revision: https://code.wildfiregames.com/D2814
This was SVN commit r24215.
2020-11-19 10:27:26 +01:00
|
|
|
for (const SHotkeyMapping& hotkey : g_HotkeyMap[scancode])
|
2005-10-21 20:32:16 +02:00
|
|
|
{
|
2010-11-07 21:42:52 +01:00
|
|
|
// If a key has been pressed, and this event triggers on its release, skip it.
|
2004-11-11 08:09:32 +01:00
|
|
|
// Similarly, if the key's been released and the event triggers on a keypress, skip it.
|
2015-07-29 03:07:23 +02:00
|
|
|
if (hotkey.negated == typeKeyDown)
|
2004-11-11 08:09:32 +01:00
|
|
|
continue;
|
|
|
|
|
2014-08-04 18:48:54 +02:00
|
|
|
// Check for no unpermitted keys
|
2004-11-11 08:09:32 +01:00
|
|
|
bool accept = true;
|
2015-07-29 03:07:23 +02:00
|
|
|
for (const SKey& k : hotkey.requires)
|
2015-10-10 09:22:07 +02:00
|
|
|
{
|
2015-07-29 03:07:23 +02:00
|
|
|
accept = isNegated(k);
|
2015-10-10 09:22:07 +02:00
|
|
|
if (!accept)
|
|
|
|
break;
|
|
|
|
}
|
2004-08-03 01:14:54 +02:00
|
|
|
|
2015-07-29 03:07:23 +02:00
|
|
|
if (accept && !(consoleCapture && hotkey.name != "console.toggle"))
|
2004-07-23 12:56:52 +02:00
|
|
|
{
|
2010-11-07 21:42:52 +01:00
|
|
|
// Check if this is an equally precise or more precise match
|
2015-07-29 03:07:23 +02:00
|
|
|
if (hotkey.requires.size() + 1 >= closestMapMatch)
|
2004-11-11 08:09:32 +01:00
|
|
|
{
|
2010-11-07 21:42:52 +01:00
|
|
|
// Check if more precise
|
2015-07-29 03:07:23 +02:00
|
|
|
if (hotkey.requires.size() + 1 > closestMapMatch)
|
2010-11-07 21:42:52 +01:00
|
|
|
{
|
|
|
|
// Throw away the old less-precise matches
|
|
|
|
closestMapNames.clear();
|
2015-07-29 03:07:23 +02:00
|
|
|
closestMapMatch = hotkey.requires.size() + 1;
|
2010-11-07 21:42:52 +01:00
|
|
|
}
|
|
|
|
|
2015-07-29 03:07:23 +02:00
|
|
|
closestMapNames.push_back(hotkey.name.c_str());
|
2004-11-11 08:09:32 +01:00
|
|
|
}
|
2004-07-23 12:56:52 +02:00
|
|
|
}
|
2004-11-11 08:09:32 +01:00
|
|
|
}
|
2004-08-03 01:14:54 +02:00
|
|
|
|
2010-11-07 21:42:52 +01:00
|
|
|
for (size_t i = 0; i < closestMapNames.size(); ++i)
|
2004-11-11 08:09:32 +01:00
|
|
|
{
|
2020-05-26 23:47:03 +02:00
|
|
|
// Send a KeyPress event when a key is pressed initially and on mouseButton and mouseWheel events.
|
|
|
|
if (ev->ev.type != SDL_KEYDOWN || ev->ev.key.repeat == 0)
|
|
|
|
{
|
|
|
|
SDL_Event_ hotkeyPressNotification;
|
|
|
|
hotkeyPressNotification.ev.type = SDL_HOTKEYPRESS;
|
|
|
|
hotkeyPressNotification.ev.user.data1 = const_cast<char*>(closestMapNames[i]);
|
|
|
|
in_push_priority_event(&hotkeyPressNotification);
|
|
|
|
}
|
|
|
|
|
|
|
|
// Send a HotkeyDown event on every key, mouseButton and mouseWheel event.
|
|
|
|
// For keys the event is repeated depending on hardware and OS configured interval.
|
|
|
|
// On linux, modifier keys (shift, alt, ctrl) are not repeated, see https://github.com/SFML/SFML/issues/122.
|
|
|
|
SDL_Event_ hotkeyDownNotification;
|
|
|
|
hotkeyDownNotification.ev.type = SDL_HOTKEYDOWN;
|
|
|
|
hotkeyDownNotification.ev.user.data1 = const_cast<char*>(closestMapNames[i]);
|
|
|
|
in_push_priority_event(&hotkeyDownNotification);
|
2004-11-11 08:09:32 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
// -- KEYUP SECTION --
|
2004-07-21 18:51:21 +02:00
|
|
|
|
Let players remap hotkeys in-game, fix default hotkeys being qwerty-specific.
- Provide a "Hotkey" screen to let players remap hotkeys in-game using a
convenient setup.
- Make all .cfg hotkeys refer to scancodes (i.e. position on the
keyboard), so that default hotkeys now translate correctly for AZERTY,
QWERTZ and other layouts.
- 'BackSpace' is now an alias for 'Delete', and works for killing units.
This fixes #1917, as macs don't have a proper delete key and would need
to use Fn+Del otherwise. This shifts "timewarp" to Shift+BackSpace.
Functionally, this switches hotkeys to scancodes, as that makes more
sense (they are combinations of key positions, not actual text output).
SDL includes are cleaned and key names are reused.
Fixes #2850, Fixes #2604, Refs #1810, Fixes #1917.
Follows work in 3d7784d2af.
Various diffs tested by: Angen, Stan, Freagarach
Comments by: Nescio
Differential Revision: https://code.wildfiregames.com/D2814
This was SVN commit r24215.
2020-11-19 10:27:26 +01:00
|
|
|
for (const SHotkeyMapping& hotkey : g_HotkeyMap[scancode])
|
2004-11-11 08:09:32 +01:00
|
|
|
{
|
|
|
|
// If it's a keydown event, won't cause HotKeyUps in anything that doesn't
|
|
|
|
// use this key negated => skip them
|
|
|
|
// If it's a keyup event, won't cause HotKeyUps in anything that does use
|
|
|
|
// this key negated => skip them too.
|
2015-07-29 03:07:23 +02:00
|
|
|
if (hotkey.negated != typeKeyDown)
|
2004-11-11 08:09:32 +01:00
|
|
|
continue;
|
|
|
|
|
2014-08-04 18:48:54 +02:00
|
|
|
// Check for no unpermitted keys
|
2004-11-11 08:09:32 +01:00
|
|
|
bool accept = true;
|
2015-07-29 03:07:23 +02:00
|
|
|
for (const SKey& k : hotkey.requires)
|
2015-10-10 09:22:07 +02:00
|
|
|
{
|
2015-07-29 03:07:23 +02:00
|
|
|
accept = isNegated(k);
|
2015-10-10 09:22:07 +02:00
|
|
|
if (!accept)
|
|
|
|
break;
|
|
|
|
}
|
2004-07-21 18:51:21 +02:00
|
|
|
|
2014-08-04 18:48:54 +02:00
|
|
|
if (accept)
|
2004-11-11 08:09:32 +01:00
|
|
|
{
|
Improve correctness of hotkeys at low framerates.
SDL queues up all the input events received in a frame. When the hotkey
system saw a key up/down event, it immediately updated its
HotkeyIsPressed state and then pushed a hotkey event onto the end of the
queue.
If the initial queue was e.g. [key-down shift, key-press Z, key-up
shift], the hotkey event triggered by Z would be processed after the
key-up shift had updated the HotkeyIsPressed state, so the handler of
the Z hotkey would not think the shift hotkey was pressed.
If the initial queue was e.g. [key-press Z, mouse-click], the hotkey
triggered by Z would be processed after the mouse-click event, so it
could apply to the wrong building selection.
Fix by pushing the hotkey events onto a special queue that gets
processed before any subsequent SDL input events.
Also update the HotkeyIsPressed status when the HOTKEYDOWN/HOTKEYUP
events are processed, not when they are generated, to guarantee they are
consistent with the DOWN/UP events.
Fixes #1869.
This was SVN commit r14057.
2013-10-30 02:38:32 +01:00
|
|
|
SDL_Event_ hotkeyNotification;
|
|
|
|
hotkeyNotification.ev.type = SDL_HOTKEYUP;
|
2015-07-29 03:07:23 +02:00
|
|
|
hotkeyNotification.ev.user.data1 = const_cast<char*>(hotkey.name.c_str());
|
Improve correctness of hotkeys at low framerates.
SDL queues up all the input events received in a frame. When the hotkey
system saw a key up/down event, it immediately updated its
HotkeyIsPressed state and then pushed a hotkey event onto the end of the
queue.
If the initial queue was e.g. [key-down shift, key-press Z, key-up
shift], the hotkey event triggered by Z would be processed after the
key-up shift had updated the HotkeyIsPressed state, so the handler of
the Z hotkey would not think the shift hotkey was pressed.
If the initial queue was e.g. [key-press Z, mouse-click], the hotkey
triggered by Z would be processed after the mouse-click event, so it
could apply to the wrong building selection.
Fix by pushing the hotkey events onto a special queue that gets
processed before any subsequent SDL input events.
Also update the HotkeyIsPressed status when the HOTKEYDOWN/HOTKEYUP
events are processed, not when they are generated, to guarantee they are
consistent with the DOWN/UP events.
Fixes #1869.
This was SVN commit r14057.
2013-10-30 02:38:32 +01:00
|
|
|
in_push_priority_event(&hotkeyNotification);
|
2004-07-21 18:51:21 +02:00
|
|
|
}
|
|
|
|
}
|
2004-11-11 08:09:32 +01:00
|
|
|
|
2014-08-04 18:48:54 +02:00
|
|
|
return IN_PASS;
|
2004-07-21 18:51:21 +02:00
|
|
|
}
|
2004-08-09 22:58:32 +02:00
|
|
|
|
2010-01-09 20:20:14 +01:00
|
|
|
bool HotkeyIsPressed(const CStr& keyname)
|
2006-08-25 06:24:06 +02:00
|
|
|
{
|
2010-10-23 04:37:00 +02:00
|
|
|
return g_HotkeyStatus[keyname];
|
2006-08-25 06:24:06 +02:00
|
|
|
}
|