Input followup (#687)

- Allow some control chars to be used as input.

This is actually a regression, since our default config uses some of
these chars.

- Allow default keys bindings to be used elsewhere.

If we try to use keys such as `KP_ADD`, `KP_ENTER` as game input, we
actually execute a `NOOP` command accelerator (nothing done), as we
associate the key with it to disable the accel.
Due to this, we do not allow any further processing of this key, such
as game input.
This commit is contained in:
Edênis Freindorfer Azevedo 2020-06-20 19:36:24 -03:00 committed by GitHub
parent de93330125
commit 91a6b53e02
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 16 additions and 6 deletions

View File

@ -2124,7 +2124,7 @@ public:
if ((sys_accels[i].GetFlags() == selmod && sys_accels[i].GetKeyCode() == selkey)
|| (seljoy != 0 && sys_accels[i].GetUkey() == selstr)) // joystick system bindings?
{
wxAcceleratorEntryUnicode ne(sys_accels[i].GetUkey(), sys_accels[i].GetJoystick(), selmod, selkey, XRCID("NOOP"));
wxAcceleratorEntryUnicode ne(selstr, seljoy, selmod, selkey, XRCID("NOOP"));
user_accels.push_back(ne);
}
@ -2597,6 +2597,7 @@ void MainFrame::set_global_accels()
// the last is chosen so menu overrides non-menu and user overrides
// system
int cmd = cmdtab[i].cmd_id;
if (cmd == XRCID("NOOP")) continue;
int last_accel = -1;
for (size_t j = 0; j < accels.size(); ++j)

View File

@ -1318,7 +1318,6 @@ void GameArea::OnKeyDown(wxKeyEvent& ev)
if (process_key_press(true, kc, ev.GetModifiers())) {
wxWakeUpIdle();
}
ev.Skip();
}
void GameArea::OnKeyUp(wxKeyEvent& ev)

View File

@ -68,7 +68,7 @@
static inline void DoSetAccel(wxMenuItem* mi, wxAcceleratorEntryUnicode* acc)
{
// cannot use SDL keybinding as text without wx assertion error
if (!acc || acc->GetJoystick() != 0) return;
if (acc && acc->GetJoystick() != 0) return;
wxString lab = mi->GetItemLabel();
size_t tab = lab.find(wxT('\t'));

View File

@ -6,8 +6,17 @@ int getKeyboardKeyCode(wxKeyEvent& event)
{
int uc = event.GetUnicodeKey();
if (uc != WXK_NONE) {
if (uc < 32)
return WXK_NONE;
if (uc < 32) { // not all control chars
switch (uc) {
case WXK_BACK:
case WXK_TAB:
case WXK_RETURN:
case WXK_ESCAPE:
return uc;
default:
return WXK_NONE;
}
}
return uc;
}
else {

View File

@ -852,7 +852,8 @@ int MainFrame::FilterEvent(wxEvent& event)
int keyMod = ke.GetModifiers();
wxAcceleratorEntry_v accels = wxGetApp().GetAccels();
for (size_t i = 0; i < accels.size(); ++i)
if (keyCode == accels[i].GetKeyCode() && keyMod == accels[i].GetFlags())
if (keyCode == accels[i].GetKeyCode() && keyMod == accels[i].GetFlags()
&& accels[i].GetCommand() != XRCID("NOOP"))
{
wxCommandEvent evh(wxEVT_COMMAND_MENU_SELECTED, accels[i].GetCommand());
evh.SetEventObject(this);