From 62081a51b0c05744fb27a154c5406c2db783190c Mon Sep 17 00:00:00 2001 From: Mitchell Hashimoto Date: Wed, 16 Aug 2023 08:12:07 -0700 Subject: [PATCH] core: add KeyEvent --- src/Surface.zig | 34 ++++++++++++++++++++++++++++++++++ 1 file changed, 34 insertions(+) diff --git a/src/Surface.zig b/src/Surface.zig index 9d7c58b75..687faad00 100644 --- a/src/Surface.zig +++ b/src/Surface.zig @@ -1139,6 +1139,40 @@ pub fn charCallback( try self.io_thread.wakeup.notify(); } +/// A key input event. +pub const KeyEvent = struct { + /// The action: press, release, etc. + action: input.Action, + + /// "key" is the logical key that was pressed. For example, if + /// a Dvorak keyboard layout is being used on a US keyboard, + /// the "i" physical key will be reported as "c". The physical + /// key is the key that was physically pressed on the keyboard. + key: input.Key, + physical_key: input.Key, + + /// Mods are the modifiers that are pressed. + mods: input.Mods, + + /// The mods that were consumed in order to generate the text + /// in utf8. This has the mods set that were consumed, so to + /// get the set of mods that are effective you must negate + /// mods with this. + /// + /// This field is meaningless if utf8 is empty. + consumed_mods: input.Mods, + + /// Composing is true when this key event is part of a dead key + /// composition sequence and we're in the middle of it. + composing: bool, + + /// The utf8 sequence that was generated by this key event. + /// This will be an empty string if there is no text generated. + /// If composing is true and this is non-empty, this is preedit + /// text. + utf8: []const u8, +}; + /// Called for a single key event. /// /// This will return true if the key was handled/consumed. In that case,