summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--Libraries/LibGUI/Event.cpp29
-rw-r--r--Libraries/LibGUI/Event.h2
2 files changed, 31 insertions, 0 deletions
diff --git a/Libraries/LibGUI/Event.cpp b/Libraries/LibGUI/Event.cpp
index 94acc7d57d..f511c8c06b 100644
--- a/Libraries/LibGUI/Event.cpp
+++ b/Libraries/LibGUI/Event.cpp
@@ -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();
+}
+
}
diff --git a/Libraries/LibGUI/Event.h b/Libraries/LibGUI/Event.h
index 2b2adf7bac..c62d83bc38 100644
--- a/Libraries/LibGUI/Event.h
+++ b/Libraries/LibGUI/Event.h
@@ -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 };