opencode icon indicating copy to clipboard operation
opencode copied to clipboard

feat(keybinds): support physical keycode-based keybindings for non-English layouts

Open wanbok opened this issue 2 weeks ago • 0 comments

feat: Support physical keycode-based keybindings for non-English keyboard layouts

Summary

Add support for physical key position matching in keybindings, enabling shortcuts to work correctly with non-English keyboard layouts (Korean, Japanese, Chinese, AZERTY, Dvorak, etc.).

Problem

When using non-English input methods, keybindings fail because OpenCode matches by character name:

  • User configures ctrl+x
  • In Korean mode, Ctrl + X key produces ctrl+ㅌ
  • Keybind doesn't match → shortcut fails

Solution

Leverage OpenTUI's existing Kitty keyboard protocol support (baseCode field) for physical key matching.

Changes

File Change
src/util/keybind.ts Add baseCode to Info type, update match() with MatchOptions
src/cli/cmd/tui/context/keybind.tsx Pass usePhysicalKeys config to match()
src/config/config.ts Add usePhysicalKeys keybind option
test/keybind.test.ts Add 18 tests for physical key matching

Usage

{
  "keybinds": {
    "usePhysicalKeys": true
  }
}

Compatibility

  • Opt-in: Default false for backward compatibility
  • Graceful fallback: Falls back to character matching when baseCode unavailable
  • Terminal support: Works with Kitty, Ghostty, WezTerm, iTerm2, Alacritty

Testing

Added tests for:

  • Physical key matching with Korean input (한글)
  • AZERTY layout simulation
  • Fallback behavior
  • Modifier key handling with physical keys
  • Leader key combinations

Related

  • Closes #XXXX (if issue exists)

wanbok avatar Jan 03 '26 14:01 wanbok