From 915b3b6b44894b31646eb3ede1ae4736f0af92b4 Mon Sep 17 00:00:00 2001 From: Mike Naberezny Date: Mon, 9 Feb 2015 14:47:55 -0800 Subject: [PATCH] Fix console input when run under Python 3 on Windows. Closes #27 --- CHANGES.txt | 2 ++ py65/utils/console.py | 12 ++++++++---- 2 files changed, 10 insertions(+), 4 deletions(-) diff --git a/CHANGES.txt b/CHANGES.txt index 4ed1d01..c66065f 100644 --- a/CHANGES.txt +++ b/CHANGES.txt @@ -6,6 +6,8 @@ - ASCII literals are now supported by the assembler. The statement "LDA #'A'" is equivalent to "LDA #$41". + - Fixed console input when run under Python 3 on Windows. Closes #27. + 0.20 (2014-05-08) - Page wrapping for indexed indirect (X) operations on 65C02 has been diff --git a/py65/utils/console.py b/py65/utils/console.py index a9cf7c3..db2d884 100644 --- a/py65/utils/console.py +++ b/py65/utils/console.py @@ -8,15 +8,19 @@ if sys.platform[:3] == "win": is available. Does not echo the character. The stdin argument is for function signature compatibility and is ignored. """ - return msvcrt.getch() + c = msvcrt.getch() + if isinstance(c, bytes): # Python 3 + c = c.decode('latin-1') + return c def getch_noblock(stdin): """ Read one character from the Windows console without blocking. - Does not echo the character. If no character is available, an - emptry string is returned. + Does not echo the character. The stdin argument is for function + signature compatibility and is ignored. If no character is + available, an emptry string is returned. """ if msvcrt.kbhit(): - return msvcrt.getch() + return getch(stdin) return '' else: