only handle non-printables on press/release, and BS is 0x7F

This commit is contained in:
Mitchell Hashimoto
2022-08-24 10:18:05 -07:00
parent 622537d665
commit b33268cee3

View File

@ -598,52 +598,54 @@ fn keyCallback(
} }
// Handle non-printable characters // Handle non-printable characters
const char: u8 = switch (@bitCast(u8, mods)) { if (action == .press or action == .repeat) {
// No modifiers pressed at all const char: u8 = switch (@bitCast(u8, mods)) {
0 => @as(u8, switch (key) { // No modifiers pressed at all
.backspace => 0x08, 0 => @as(u8, switch (key) {
.enter => '\r', .backspace => 0x7F,
.tab => '\t', .enter => '\r',
.escape => 0x1B, .tab => '\t',
else => 0, .escape => 0x1B,
}), else => 0,
}),
// Control only // Control only
@bitCast(u8, glfw.Mods{ .control = true }) => @as(u8, switch (key) { @bitCast(u8, glfw.Mods{ .control = true }) => @as(u8, switch (key) {
.a => 0x01, .a => 0x01,
.b => 0x02, .b => 0x02,
.c => 0x03, .c => 0x03,
.d => 0x04, .d => 0x04,
.e => 0x05, .e => 0x05,
.f => 0x06, .f => 0x06,
.g => 0x07, .g => 0x07,
.h => 0x08, .h => 0x08,
.i => 0x09, .i => 0x09,
.j => 0x0A, .j => 0x0A,
.k => 0x0B, .k => 0x0B,
.l => 0x0C, .l => 0x0C,
.m => 0x0D, .m => 0x0D,
.n => 0x0E, .n => 0x0E,
.o => 0x0F, .o => 0x0F,
.p => 0x10, .p => 0x10,
.q => 0x11, .q => 0x11,
.r => 0x12, .r => 0x12,
.s => 0x13, .s => 0x13,
.t => 0x14, .t => 0x14,
.u => 0x15, .u => 0x15,
.v => 0x16, .v => 0x16,
.w => 0x17, .w => 0x17,
.x => 0x18, .x => 0x18,
.y => 0x19, .y => 0x19,
.z => 0x1A, .z => 0x1A,
else => 0, else => 0,
}), }),
else => 0, else => 0,
}; };
if (char > 0) { if (char > 0) {
win.queueWrite(&[1]u8{char}) catch |err| win.queueWrite(&[1]u8{char}) catch |err|
log.err("error queueing write in keyCallback err={}", .{err}); log.err("error queueing write in keyCallback err={}", .{err});
}
} }
} }