From a264206a67851e23a1ae4389d6506a3d3605e190 Mon Sep 17 00:00:00 2001 From: Brandon Dyck Date: Tue, 18 Jan 2022 17:38:32 -0700 Subject: [PATCH] Print key buffer on key event --- lib/minifb | 2 +- src/main.zig | 15 +++++++++++++++ 2 files changed, 16 insertions(+), 1 deletion(-) diff --git a/lib/minifb b/lib/minifb index 8e8a667..d173dcc 160000 --- a/lib/minifb +++ b/lib/minifb @@ -1 +1 @@ -Subproject commit 8e8a66761cb003b00ecc7a38307e83ddd33ffa27 +Subproject commit d173dcc4da9b934a37ac13e7e11431984e25f70c diff --git a/src/main.zig b/src/main.zig index 02fcdd2..f7a13ac 100644 --- a/src/main.zig +++ b/src/main.zig @@ -226,6 +226,21 @@ fn handleKeyboard(win: mfb.Window(State), key: mfb.Key, _: mfb.KeyMod, is_presse var state = win.getUserData().?; state.*.paused = !state.*.paused; } + + const out = std.io.getStdOut().writer(); + var has_written = false; + for (win.getKeyBuffer()) |buf_key, i| { + if (buf_key) { + if (!has_written) { + _ = out.write("Keyboard buffer:") catch unreachable; + } + std.fmt.format(out, " {}", .{@intToEnum(mfb.Key, i)}) catch unreachable; + has_written = true; + } + } + if (has_written) { + out.writeByte('\n') catch unreachable; + } } fn handleCharInput(win: mfb.Window(State), char: u32) callconv(.C) void {