diff --git a/Libraries/LibGUI/Event.cpp b/Libraries/LibGUI/Event.cpp index 94acc7d57d9..f511c8c06bf 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 +#include #include #include @@ -41,4 +43,31 @@ DropEvent::~DropEvent() { } +String KeyEvent::to_string() const +{ + Vector 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(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 2b2adf7bac6..c62d83bc388 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 };