1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
|
// Input constants
// Copyright (C) 2021 Nguyễn Gia Phong
//
// This file is part of gfz.
//
// gfz is free software: you can redistribute it and/or modify
// it under the terms of the GNU Lesser General Public License as published
// by the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// gfz is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU Lesser General Public License for more details.
//
// You should have received a copy of the GNU Lesser General Public License
// along with gfz. If not, see <https://www.gnu.org/licenses/>.
const ComptimeStringMap = std.ComptimeStringMap;
const EnumField = TypeInfo.EnumField;
const TypeInfo = std.builtin.TypeInfo;
const glfw = @import("cimport.zig");
const std = @import("std");
const keys = [_][]const u8{
// Printable keys
"SPACE", "APOSTROPHE", "COMMA", "MINUS", "PERIOD", "SLASH",
"0", "1", "2", "3", "4", "5", "6", "7", "8", "9", "SEMICOLON", "EQUAL",
"A", "B", "C", "D", "E", "F", "G", "H", "I", "J", "K", "L", "M",
"N", "O", "P", "Q", "R", "S", "T", "U", "V", "W", "X", "Y", "Z",
"LEFT_BRACKET", "BACKSLASH", "RIGHT_BRACKET", "GRAVE_ACCENT",
"WORLD_1", "WORLD_2", // keys lacking a clear US mapping
// Function keys
"ESCAPE", "ENTER", "TAB", "BACKSPACE", "INSERT", "DELETE",
"RIGHT", "LEFT", "DOWN", "UP", "PAGE_UP", "PAGE_DOWN", "HOME", "END",
"CAPS_LOCK", "SCROLL_LOCK", "NUM_LOCK", "PRINT_SCREEN", "PAUSE",
"F1", "F2", "F3", "F4", "F5", "F6", "F7", "F8", "F9",
"F10", "F11", "F12", "F13", "F14", "F15", "F16", "F17",
"F18", "F19", "F20", "F21", "F22", "F23", "F24", "F25",
"KP_0", "KP_1", "KP_2", "KP_3", "KP_4", "KP_5", "KP_6",
"KP_7", "KP_8", "KP_9", "KP_DECIMAL", "KP_DIVIDE", "KP_MULTIPLY",
"KP_SUBTRACT", "KP_ADD", "KP_ENTER", "KP_EQUAL",
"LEFT_SHIFT", "LEFT_CONTROL", "LEFT_ALT", "LEFT_SUPER",
"RIGHT_SHIFT", "RIGHT_CONTROL", "RIGHT_ALT", "RIGHT_SUPER", "MENU",
};
/// Keyboard key enumeration
pub const Key = @Type(TypeInfo{
.Enum = .{
.layout = .Auto,
.tag_type = c_int,
.fields = blk: {
var fields: [keys.len]EnumField = undefined;
for (keys) |name, i|
fields[i] = .{
.name = name,
.value = @field(glfw, "GLFW_KEY_" ++ name),
};
break :blk fields[0..];
},
.decls = &.{},
.is_exhaustive = true,
}
});
/// Mapping of name to keyboard key
pub const KeyMap = blk: {
var map: [keys.len]struct {
@"0": []const u8,
@"1": Key,
} = undefined;
for (keys) |name, i|
map[i] = .{ name, @field(Key, name) };
break :blk ComptimeStringMap(Key, map);
};
|