From 885943e73f59581d399b4f9d65870c1acfb9f2e9 Mon Sep 17 00:00:00 2001 From: Orkuncakilkaya Date: Sun, 13 Sep 2026 03:00:29 +0300 Subject: [PATCH] fix(cocoa): the Delete key reports Key.Backspace (8) AppKit gives kVK_Delete (51) the character NSDeleteCharacter, 127, which is what both ev_keyval (the held-key set) and win_poll (the per-frame key) received, so Key.Backspace, which folds to 8, never matched. Both now map key code 51 to 8. Co-Authored-By: Claude Opus 5 --- changes/backspace-key.md | 7 +++++++ runtime/native/cocoa.ll | 6 ++++++ 2 files changed, 13 insertions(+) create mode 100644 changes/backspace-key.md diff --git a/changes/backspace-key.md b/changes/backspace-key.md new file mode 100644 index 00000000..85cd81b9 --- /dev/null +++ b/changes/backspace-key.md @@ -0,0 +1,7 @@ +bump: patch +type: fix +**Backspace fires on macOS** — the Delete key reports `Key.Backspace` (8). + +AppKit gives the key marked delete (kVK_Delete, 51) the character `NSDeleteCharacter`, 127, +which is what both the held-key set and the per-frame key received, so `Key.Backspace` never +matched. `cocoa.ll` maps key code 51 to 8 in both. diff --git a/runtime/native/cocoa.ll b/runtime/native/cocoa.ll index 3eb1e533..5a417a88 100644 --- a/runtime/native/cocoa.ll +++ b/runtime/native/cocoa.ll @@ -346,6 +346,7 @@ entry: i32 49, label %vspace i32 36, label %vret i32 53, label %vesc + i32 51, label %vbksp ] vw: ret i32 128 vs: ret i32 129 @@ -354,6 +355,9 @@ vd: ret i32 131 vspace: ret i32 32 vret: ret i32 10 vesc: ret i32 27 +; kVK_Delete (51), the key marked delete or backspace: AppKit reports its character as +; NSDeleteCharacter (127), and Key.Backspace is 8 +vbksp: ret i32 8 chars: %sel_ch = call ptr @sel_registerName(ptr @.s_chars) %sel_len = call ptr @sel_registerName(ptr @.s_length) @@ -493,6 +497,7 @@ key: i32 49, label %k_space i32 36, label %k_ret i32 53, label %k_esc + i32 51, label %k_bksp ] k_w: store i32 119, ptr @W_key br label %forward k_s: store i32 115, ptr @W_key br label %forward @@ -500,6 +505,7 @@ k_a: store i32 97, ptr @W_key br label %forward k_d: store i32 100, ptr @W_key br label %forward k_space: store i32 32, ptr @W_key br label %forward k_ret: store i32 10, ptr @W_key br label %forward +k_bksp: store i32 8, ptr @W_key br label %forward k_esc: ; Escape is delivered as key 27 and left to the game (pause menus etc.). ; It used to force-quit the window, which a shipped game cannot tolerate.