Skip to content

Commit 46b22d1

Browse files
committed
Lib\_pyrepl\windows_console.py: fix Alt+ handling
1 parent e3f6438 commit 46b22d1

File tree

1 file changed

+9
-6
lines changed

1 file changed

+9
-6
lines changed

Lib/_pyrepl/windows_console.py

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,6 @@ def __init__(self, err: int | None, descr: str | None = None) -> None:
105105
# State of control keys: https://learn.microsoft.com/en-us/windows/console/key-event-record-str
106106
ALT_ACTIVE = 0x01 | 0x02
107107
CTRL_ACTIVE = 0x04 | 0x08
108-
CTRL_OR_ALT_ACTIVE = ALT_ACTIVE | CTRL_ACTIVE
109108

110109

111110
class _error(Exception):
@@ -423,11 +422,15 @@ def get_event(self, block: bool = True) -> Event | None:
423422
key = "backspace"
424423
elif key == "\x00":
425424
# Handle special keys like arrow keys and translate them into the appropriate command
426-
code = VK_MAP.get(key_event.wVirtualKeyCode)
427-
if code:
428-
if code in ("left", "right") and key_event.dwControlKeyState & CTRL_OR_ALT_ACTIVE:
429-
code = f"ctrl {code}"
430-
return Event(evt="key", data=code, raw=key)
425+
key = VK_MAP.get(key_event.wVirtualKeyCode)
426+
if key:
427+
if key in ("left", "right") and key_event.dwControlKeyState & CTRL_ACTIVE:
428+
key = f"ctrl {key}"
429+
elif key_event.dwControlKeyState & ALT_ACTIVE:
430+
# queue the key, return the meta command
431+
self.event_queue.insert(0, Event(evt="key", data=key, raw=key))
432+
return Event(evt="key", data="\033") # keymap.py uses this for meta
433+
return Event(evt="key", data=key, raw=key)
431434
if block:
432435
continue
433436

0 commit comments

Comments
 (0)