summary refs log tree commit diff
path: root/src/misc.zig
diff options
context:
space:
mode:
Diffstat (limited to 'src/misc.zig')
-rw-r--r--src/misc.zig9
1 files changed, 9 insertions, 0 deletions
diff --git a/src/misc.zig b/src/misc.zig
index e30c154..678538b 100644
--- a/src/misc.zig
+++ b/src/misc.zig
@@ -25,6 +25,8 @@ usingnamespace @cImport({
 
 const Dir = std.fs.Dir;
 const TokenIterator = std.mem.TokenIterator;
+const Key = gf.Key;
+const Window = gf.Window;
 const al = @import("zeal");
 const allocPrint = std.fmt.allocPrint;
 const allocator = std.heap.c_allocator;
@@ -35,6 +37,7 @@ const data_dir = @import("build_options").data_dir ++ [_]u8{ sep };
 const endsWith = std.mem.endsWith;
 const eql = std.mem.eql;
 const free = std.c.free;
+const gf = @import("gfz");
 const ini = @import("ini");
 const join = std.fs.path.joinZ;
 const hash = std.crypto.hash.Blake3.hash;
@@ -47,6 +50,12 @@ const startsWith = std.mem.startsWith;
 const std = @import("std");
 const tokenize = std.mem.tokenize;
 
+/// Return whether the given keyboard key is pressed.
+export fn keyPress(key: c_int) bool {
+    const window = (Window.getCurrent() catch unreachable).?;
+    return (window.getKey(@intToEnum(Key, key)) catch unreachable) == .press;
+}
+
 /// Read given file to heap, allocated by C allocator.
 fn readFile(dir: Dir, comptime fmt: []const u8, args: anytype) ![]const u8 {
     const filename = try allocPrint(allocator, fmt, args);