Skip to content

Fix parsing hotkeys for non english chars#5122

Open
bn45hkurr0y4 wants to merge 2 commits intoPowerShell:masterfrom
bn45hkurr0y4:bn45hkurr0y4-patch-1
Open

Fix parsing hotkeys for non english chars#5122
bn45hkurr0y4 wants to merge 2 commits intoPowerShell:masterfrom
bn45hkurr0y4:bn45hkurr0y4-patch-1

Conversation

@bn45hkurr0y4
Copy link
Copy Markdown

@bn45hkurr0y4 bn45hkurr0y4 commented Apr 8, 2026

This fixes an issue related to incorrect key handling in non-English keyboard layouts (in my case, the Russian CTRL + C shortcut).
I've had this problem for a long time and no one has fixed it yet, but with the help of AI, I discovered that the issue stems from incorrect handling of the Cyrillic alphabet.
Please test this patch, because I don’t know if it might affect something else and cause errors.

This fixes #1393 and #2865

PR Summary

PR Checklist

  • PR has a meaningful title
  • Summarized changes
  • Make sure you've added one or more new tests
  • Make sure you've tested these changes in terminals that PowerShell is commonly used in (i.e. conhost.exe, Windows Terminal, Visual Studio Code Integrated Terminal, etc.)
  • User-facing changes
    • Not Applicable
Microsoft Reviewers: Open in CodeFlow

Add comments to clarify handling of Ctrl+letter combinations and dead keys.
Copilot AI review requested due to automatic review settings April 8, 2026 09:55
Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR addresses a long-standing issue where Ctrl+letter hotkeys (notably Ctrl+C) can be mis-parsed under non-English Windows keyboard layouts (e.g., Russian), causing PSReadLine key binding matching to fail.

Changes:

  • Skips the Windows ToUnicodeEx-based translation for standard Ctrl+letter control characters (\x01\x1A) to keep chord normalization layout-independent.
  • Adds inline comments explaining why Ctrl+letter chords should bypass layout-dependent translation to preserve key binding matching.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment on lines +249 to +253
// to letters a-z is well-defined and layout-independent, so we skip the
// ToUnicodeEx call which would return a layout-dependent character
// (e.g. Cyrillic 'с' instead of Latin 'c' on Russian layout), breaking
// key binding matching.
if (!isDeadKey && !(c >= 1 && c <= 26))
Copy link

Copilot AI Apr 8, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This change alters how Ctrl+letter chords are normalized on Windows, but there’s no automated coverage to prevent regressions (especially for non-English layouts like ru-RU). Please add a unit/integration test that validates Ctrl+C (and ideally a couple other Ctrl+letter chords) still normalize to the expected Latin chord string even when the active keyboard layout is Russian (skip the test if the layout isn’t available on the runner).

Copilot uses AI. Check for mistakes.
change magic number to hex

Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Ctrl-C doesn't work if PowerShell was started with Russian keyboard layout

2 participants