Skip to content

Key enum missing punctuation/symbol keys (Slash, Minus, Equals, etc.) #571

@ad-si

Description

@ad-si

Problem

The Key enum in three-d only includes alphanumeric keys (A-Z, 0-9), arrow keys, and a handful of special keys (Escape, Tab, Enter, etc.). It's missing all punctuation and symbol keys such as:

  • Slash (/)
  • Minus (-)
  • Equals (=)
  • Backslash (\)
  • Semicolon (;)
  • Period (.)
  • Comma (,)
  • Bracket keys, etc.

This means Event::KeyPress is never emitted for these keys, because translate_virtual_key_code() returns None for any VirtualKeyCode that doesn't map to a Key variant.

Additionally, ReceivedCharacter events are suppressed when modifiers.command or modifiers.ctrl is true (in frame_input_generator.rs line ~291), so there is no way at all to detect modifier+symbol key combinations like Cmd+/, Cmd+-, Ctrl+=, etc.

Impact

This makes it impossible to implement common keyboard shortcuts that use punctuation keys:

  • Cmd+/ — toggle line comment (standard in virtually every code editor)
  • Cmd+- / Cmd+= — zoom out/in
  • Cmd+\ — split pane

These are especially important for applications using the egui-gui feature for text editing, since egui's own Key enum includes these keys but three-d never forwards them.

Suggested Fix

  1. Add the missing variants to the Key enum (at minimum: Slash, Minus, Equals, Backslash, Semicolon, Period, Comma, BracketLeft, BracketRight)
  2. Add the corresponding mappings in translate_virtual_key_code()
  3. (Optional) Also add mappings in the From<&Key> for egui::Key impl so they pass through to egui correctly

This would be a non-breaking addition since it only adds new enum variants.

Workaround

Currently the only workaround is to use a cargo [patch] with a local copy of three-d, or to remap shortcuts to letter keys (e.g. Cmd+Shift+C instead of Cmd+/).

Environment

  • three-d 0.18.2
  • macOS (also affects Linux/Windows)
  • Using egui-gui feature for a code editor UI

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions