const Key = @This(); kind: Kind, codepoint: u21 = 0, mods: Mods = .{}, pub fn shift(key: Key) Key { var copy = key; copy.mods.shift = true; return copy; } pub fn ctrl(key: Key) Key { var copy = key; copy.mods.ctrl = true; return copy; } pub fn alt(key: Key) Key { var copy = key; copy.mods.alt = true; return copy; } pub fn cp(symbol: u21) Key { return .{ .kind = .rune, .codepoint = symbol }; } pub fn rune(symbol: u21) Key { return cp(symbol); } pub fn eql(self: Key, other: Key) bool { if (self.kind != other.kind) return false; if (self.kind == .rune and self.codepoint != other.codepoint) return false; return @as(u8, @bitCast(self.mods)) == @as(u8, @bitCast(other.mods)); } fn special(kind: Kind) Key { return .{ .kind = kind }; } pub const enter: Key = .special(.enter); pub const space: Key = .special(.space); pub const tab: Key = .special(.tab); pub const backspace: Key = .special(.backspace); pub const escape: Key = .special(.escape); pub const up: Key = .special(.up); pub const down: Key = .special(.down); pub const left: Key = .special(.left); pub const right: Key = .special(.right); pub const home: Key = .special(.home); pub const begin: Key = .special(.begin); pub const end: Key = .special(.end); pub const page_up: Key = .special(.page_up); pub const page_down: Key = .special(.page_down); pub const insert: Key = .special(.insert); pub const delete: Key = .special(.delete); pub const a: Key = .rune('a'); pub const b: Key = .rune('b'); pub const c: Key = .rune('c'); pub const d: Key = .rune('d'); pub const e: Key = .rune('e'); pub const f: Key = .rune('f'); pub const g: Key = .rune('g'); pub const h: Key = .rune('h'); pub const i: Key = .rune('i'); pub const j: Key = .rune('j'); pub const k: Key = .rune('k'); pub const l: Key = .rune('l'); pub const m: Key = .rune('m'); pub const n: Key = .rune('n'); pub const o: Key = .rune('o'); pub const p: Key = .rune('p'); pub const q: Key = .rune('q'); pub const r: Key = .rune('r'); pub const s: Key = .rune('s'); pub const t: Key = .rune('t'); pub const u: Key = .rune('u'); pub const v: Key = .rune('v'); pub const w: Key = .rune('w'); pub const x: Key = .rune('x'); pub const y: Key = .rune('y'); pub const z: Key = .rune('z'); pub const A: Key = .shift(.rune('A')); pub const B: Key = .shift(.rune('B')); pub const C: Key = .shift(.rune('C')); pub const D: Key = .shift(.rune('D')); pub const E: Key = .shift(.rune('E')); pub const F: Key = .shift(.rune('F')); pub const G: Key = .shift(.rune('G')); pub const H: Key = .shift(.rune('H')); pub const I: Key = .shift(.rune('I')); pub const J: Key = .shift(.rune('J')); pub const K: Key = .shift(.rune('K')); pub const L: Key = .shift(.rune('L')); pub const M: Key = .shift(.rune('M')); pub const N: Key = .shift(.rune('N')); pub const O: Key = .shift(.rune('O')); pub const P: Key = .shift(.rune('P')); pub const Q: Key = .shift(.rune('Q')); pub const R: Key = .shift(.rune('R')); pub const S: Key = .shift(.rune('S')); pub const T: Key = .shift(.rune('T')); pub const U: Key = .shift(.rune('U')); pub const V: Key = .shift(.rune('V')); pub const W: Key = .shift(.rune('W')); pub const X: Key = .shift(.rune('X')); pub const Y: Key = .shift(.rune('Y')); pub const Z: Key = .shift(.rune('Z')); pub const @"?": Key = .rune('?'); pub const f1: Key = .special(.f1); pub const f2: Key = .special(.f2); pub const f3: Key = .special(.f3); pub const f4: Key = .special(.f4); pub const f5: Key = .special(.f5); pub const f6: Key = .special(.f6); pub const f7: Key = .special(.f7); pub const f8: Key = .special(.f8); pub const f9: Key = .special(.f9); pub const f10: Key = .special(.f10); pub const f11: Key = .special(.f11); pub const f12: Key = .special(.f12); pub const f13: Key = .special(.f13); pub const f14: Key = .special(.f14); pub const f15: Key = .special(.f15); pub const @"f16": Key = .special(.f16); pub const f17: Key = .special(.f17); pub const f18: Key = .special(.f18); pub const f19: Key = .special(.f19); pub const f20: Key = .special(.f20); pub const Mods = packed struct(u8) { shift: bool = false, alt: bool = false, ctrl: bool = false, meta: bool = false, hyper: bool = false, super: bool = false, caps_lock: bool = false, num_lock: bool = false, }; pub const Kind = enum(u8) { rune, space, enter, tab, backspace, escape, up, down, left, right, home, end, page_up, page_down, begin, insert, delete, f1, f2, f3, f4, f5, f6, f7, f8, f9, f10, f11, f12, f13, f14, f15, f16, f17, f18, f19, f20, };