LibGUI: Add KeyEvent::to_string()
This makes it way easier to debug key events.
This commit is contained in:
parent
90eec0a3d7
commit
479f16bb6c
Notes:
sideshowbarker
2024-07-19 06:42:37 +09:00
Author: https://github.com/awesomekling Commit: https://github.com/SerenityOS/serenity/commit/479f16bb6c0
2 changed files with 31 additions and 0 deletions
|
@ -24,6 +24,8 @@
|
|||
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
#include <AK/StringBuilder.h>
|
||||
#include <Kernel/KeyCode.h>
|
||||
#include <LibCore/MimeData.h>
|
||||
#include <LibGUI/Event.h>
|
||||
|
||||
|
@ -41,4 +43,31 @@ DropEvent::~DropEvent()
|
|||
{
|
||||
}
|
||||
|
||||
String KeyEvent::to_string() const
|
||||
{
|
||||
Vector<String, 8> parts;
|
||||
|
||||
if (m_modifiers & Mod_Ctrl)
|
||||
parts.append("Ctrl");
|
||||
if (m_modifiers & Mod_Shift)
|
||||
parts.append("Shift");
|
||||
if (m_modifiers & Mod_Alt)
|
||||
parts.append("Alt");
|
||||
if (m_modifiers & Mod_Logo)
|
||||
parts.append("Logo");
|
||||
|
||||
if (auto* key_name = key_code_to_string(static_cast<KeyCode>(m_key)))
|
||||
parts.append(key_name);
|
||||
else
|
||||
parts.append("(Invalid)");
|
||||
|
||||
StringBuilder builder;
|
||||
for (size_t i = 0; i < parts.size(); ++i) {
|
||||
builder.append(parts[i]);
|
||||
if (i != parts.size() - 1)
|
||||
builder.append('+');
|
||||
}
|
||||
return builder.to_string();
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -278,6 +278,8 @@ public:
|
|||
u8 modifiers() const { return m_modifiers; }
|
||||
String text() const { return m_text; }
|
||||
|
||||
String to_string() const;
|
||||
|
||||
private:
|
||||
friend class WindowServerConnection;
|
||||
int m_key { 0 };
|
||||
|
|
Loading…
Add table
Reference in a new issue