Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Don't trigger a key event if a key with the same associated char was pressed #13773

Merged
merged 2 commits into from
Sep 22, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
4 changes: 3 additions & 1 deletion src/client/keycode.h
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,9 @@ class KeyPress

bool operator==(const KeyPress &o) const
{
return (Char > 0 && Char == o.Char) || (valid_kcode(Key) && Key == o.Key);
if (valid_kcode(Key) && valid_kcode(o.Key))
return Key == o.Key;
return Char > 0 && Char == o.Char;
}

const char *sym() const;
Expand Down
9 changes: 8 additions & 1 deletion src/unittest/test_keycode.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ void TestKeycode::testCompare()
{
// Basic comparison
UASSERT(KeyPress("5") == KeyPress("KEY_KEY_5"));
UASSERT(!(KeyPress("5") == KeyPress("KEY_NUMPAD_5")));
UASSERT(!(KeyPress("5") == KeyPress("KEY_NUMPAD5")));
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This was broken for a while


// Matching char suffices
// note: This is a real-world example, Irrlicht maps XK_equal to irr::KEY_PLUS on Linux
Expand All @@ -126,4 +126,11 @@ void TestKeycode::testCompare()
in.Char = L'\0';
in2.Char = L';';
UASSERT(KeyPress(in) == KeyPress(in2));

// Irrlicht sets chars to the according digit for numpad keys.
// We need to distinguish them in order to bind numpad keys.
irr::SEvent::SKeyInput in3;
in3.Key = irr::KEY_NUMPAD5;
in3.Char = L'5';
UASSERT(!(KeyPress("5") == KeyPress(in3)));
}