@@ -419,10 +419,7 @@ def _getscrollbacksize(self) -> int:
419419
420420 return info .srWindow .Bottom # type: ignore[no-any-return]
421421
422- def _read_input (self , block : bool = True ) -> INPUT_RECORD | None :
423- if not block and not self .wait (timeout = 0 ):
424- return None
425-
422+ def _read_input (self ) -> INPUT_RECORD | None :
426423 rec = INPUT_RECORD ()
427424 read = DWORD ()
428425 if not ReadConsoleInput (InHandle , rec , 1 , read ):
@@ -431,14 +428,10 @@ def _read_input(self, block: bool = True) -> INPUT_RECORD | None:
431428 return rec
432429
433430 def _read_input_bulk (
434- self , block : bool , n : int
431+ self , n : int
435432 ) -> tuple [ctypes .Array [INPUT_RECORD ], int ]:
436433 rec = (n * INPUT_RECORD )()
437434 read = DWORD ()
438-
439- if not block and not self .wait (timeout = 0 ):
440- return rec , 0
441-
442435 if not ReadConsoleInput (InHandle , rec , n , read ):
443436 raise WinError (GetLastError ())
444437
@@ -449,8 +442,11 @@ def get_event(self, block: bool = True) -> Event | None:
449442 and there is no event pending, otherwise waits for the
450443 completion of an event."""
451444
445+ if not block and not self .wait (timeout = 0 ):
446+ return None
447+
452448 while self .event_queue .empty ():
453- rec = self ._read_input (block )
449+ rec = self ._read_input ()
454450 if rec is None :
455451 return None
456452
@@ -551,12 +547,20 @@ def getpending(self) -> Event:
551547 if e2 :
552548 e .data += e2 .data
553549
554- recs , rec_count = self ._read_input_bulk (False , 1024 )
550+ recs , rec_count = self ._read_input_bulk (1024 )
555551 for i in range (rec_count ):
556552 rec = recs [i ]
553+ # In case of a legacy console, we do not only receive a keydown
554+ # event, but also a keyup event - and for uppercase letters
555+ # an additional SHIFT_PRESSED event.
557556 if rec and rec .EventType == KEY_EVENT :
558557 key_event = rec .Event .KeyEvent
558+ if not key_event .bKeyDown :
559+ continue
559560 ch = key_event .uChar .UnicodeChar
561+ if ch == "\x00 " :
562+ # ignore SHIFT_PRESSED and special keys
563+ continue
560564 if ch == "\r " :
561565 ch += "\n "
562566 e .data += ch
0 commit comments