From e79140854988f9b319d109f3c75df2017b22d7e6 Mon Sep 17 00:00:00 2001 From: Rupert Li Date: Sat, 5 Jan 2019 16:13:37 +0800 Subject: [PATCH 01/13] pytest-cov 2.6.0 caused dependencies --- requirements-dev.txt | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/requirements-dev.txt b/requirements-dev.txt index f39ecdd..6323076 100644 --- a/requirements-dev.txt +++ b/requirements-dev.txt @@ -9,6 +9,6 @@ pexpect >= 3.3 coverage >=3.7.1,<4.0a1 pytest >= 2.6.2 -pytest-cov >= 1.8.0 +pytest-cov >= 1.8.0,<2.6.0 -wheel >= 0.24.0 \ No newline at end of file +wheel >= 0.24.0 From 2c2bf7e2ea673ccbc7fe0bd59678f4bb43ec9523 Mon Sep 17 00:00:00 2001 From: Rupert Li Date: Sat, 5 Jan 2019 16:34:20 +0800 Subject: [PATCH 02/13] bugfix: Error installing on Windows (from frastlin) --- setup.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/setup.py b/setup.py index b8b98e2..e373aee 100644 --- a/setup.py +++ b/setup.py @@ -1,13 +1,14 @@ # -*- coding: utf-8 -*- import sys +import io from setuptools import setup, find_packages from setuptools.command.test import test as TestCommand from getkey import __version__ def read_description(): - with open('README.rst') as fd: + with io.open('README.rst', encoding='utf-8') as fd: return fd.read() From 79bfdd64e135ecd4bf634a2756b1fd214c390aee Mon Sep 17 00:00:00 2001 From: Rupert Li Date: Sat, 5 Jan 2019 16:43:12 +0800 Subject: [PATCH 03/13] bugfix: in Python 3.x, msvcrt.getch() return a byte string not a character --- getkey/platforms.py | 20 ++++++++++++++------ 1 file changed, 14 insertions(+), 6 deletions(-) diff --git a/getkey/platforms.py b/getkey/platforms.py index 3bb4345..3fb4173 100644 --- a/getkey/platforms.py +++ b/getkey/platforms.py @@ -175,14 +175,22 @@ def __init__(self, keys=None, interrupts=None, msvcrt=None): import msvcrt self.msvcrt = msvcrt - def getchars(self, blocking=True): - """Get characters on Windows.""" + if sys.version_info < (3,0): + def getchars(self, blocking=True): + """Get characters on Windows.""" - if blocking: - yield self.msvcrt.getch() - while self.msvcrt.kbhit(): - yield self.msvcrt.getch() + if blocking: + yield self.msvcrt.getch() + while self.msvcrt.kbhit(): + yield self.msvcrt.getch() + else: + def getchars(self, blocking=True): + """Get characters on Windows.""" + if blocking: + yield chr(self.msvcrt.getch()[0]) + while self.msvcrt.kbhit(): + yield chr(self.msvcrt.getch()[0]) class PlatformTest(Platform): KEYS = 'unix' From 50a316bae4f8b0f282ca570c358893a74eae8414 Mon Sep 17 00:00:00 2001 From: Rupert Li Date: Sat, 5 Jan 2019 18:20:31 +0800 Subject: [PATCH 04/13] bugfix: get extra key occasionally when pressing function keys in mintty of cygwin --- getkey/platforms.py | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/getkey/platforms.py b/getkey/platforms.py index 3fb4173..872b9f7 100644 --- a/getkey/platforms.py +++ b/getkey/platforms.py @@ -126,7 +126,11 @@ def getchars(self, blocking=True): with self.context(): if blocking: yield self.__decoded_stream.read(1) - while self.select([self.fileno()], [], [], 0)[0]: + if sys.platform == 'cygwin': + timeout = 0.02 + else: + timeout = 0 + while self.select([self.fileno()], [], [], timeout)[0]: yield self.__decoded_stream.read(1) From 1fa3e8034f7c6c8ec6feec6df6d0e1418d245bc1 Mon Sep 17 00:00:00 2001 From: Rupert Li Date: Sat, 5 Jan 2019 18:23:01 +0800 Subject: [PATCH 05/13] wrong keynames for page_up and page_down (verified on Cygwin and Windows for both Python 2.7 and 3.6) --- getkey/keynames.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/getkey/keynames.py b/getkey/keynames.py index 51b885b..225ee57 100644 --- a/getkey/keynames.py +++ b/getkey/keynames.py @@ -190,8 +190,8 @@ class UnixKeys(object): HOME = '\x1b[H' END = '\x1b[F' - PAGE_UP = '\x1b[5' - PAGE_DOWN = '\x1b[6' + PAGE_UP = '\x1b[5~' + PAGE_DOWN = '\x1b[6~' ENTER = '\n' CR = '\r' From 68f2535d9afcf65b9c0c6726dbf40dd65ff4751c Mon Sep 17 00:00:00 2001 From: Rupert Li Date: Wed, 10 Jul 2019 20:26:14 +0800 Subject: [PATCH 06/13] bugfix: don't work on ubuntu 18.04 --- getkey/__init__.py | 2 +- getkey/platforms.py | 5 +---- 2 files changed, 2 insertions(+), 5 deletions(-) diff --git a/getkey/__init__.py b/getkey/__init__.py index c8f5ad7..37170e8 100644 --- a/getkey/__init__.py +++ b/getkey/__init__.py @@ -14,4 +14,4 @@ key = keys # alias bang = __platform.bang -__version__ = '0.6.5' +__version__ = '0.6.6' diff --git a/getkey/platforms.py b/getkey/platforms.py index 872b9f7..044d379 100644 --- a/getkey/platforms.py +++ b/getkey/platforms.py @@ -126,10 +126,7 @@ def getchars(self, blocking=True): with self.context(): if blocking: yield self.__decoded_stream.read(1) - if sys.platform == 'cygwin': - timeout = 0.02 - else: - timeout = 0 + timeout = 0.08 while self.select([self.fileno()], [], [], timeout)[0]: yield self.__decoded_stream.read(1) From c63b2efcdf9134b166cdcde445f42c234478a417 Mon Sep 17 00:00:00 2001 From: Rupert Li Date: Tue, 20 Apr 2021 23:27:27 +0800 Subject: [PATCH 07/13] bugfix #1: typo in keys declaration (thank @malversan) --- getkey/keynames.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/getkey/keynames.py b/getkey/keynames.py index 225ee57..c5e986a 100644 --- a/getkey/keynames.py +++ b/getkey/keynames.py @@ -313,7 +313,7 @@ class WindowsKeys(object): CTRL_ALT_9 = '\x00\x80' CTRL_ALT_0 = '\x00\x81' CTRL_ALT_MINUS = '\x00\x82' - CTRL_ALT_EQUALS = '\x00x83' + CTRL_ALT_EQUALS = '\x00\x83' CTRL_ALT_BACKSPACE = '\x00\x0e' ALT_F1 = '\x00h' From d54bb5550599fcbe1c31ddd6be6136cfb0f80873 Mon Sep 17 00:00:00 2001 From: Rupert Li Date: Tue, 20 Apr 2021 23:47:42 +0800 Subject: [PATCH 08/13] Revert "bugfix: in Python 3.x, msvcrt.getch() return a byte string not a character" --- getkey/platforms.py | 20 ++++++-------------- 1 file changed, 6 insertions(+), 14 deletions(-) diff --git a/getkey/platforms.py b/getkey/platforms.py index 044d379..8db9b73 100644 --- a/getkey/platforms.py +++ b/getkey/platforms.py @@ -176,22 +176,14 @@ def __init__(self, keys=None, interrupts=None, msvcrt=None): import msvcrt self.msvcrt = msvcrt - if sys.version_info < (3,0): - def getchars(self, blocking=True): - """Get characters on Windows.""" + def getchars(self, blocking=True): + """Get characters on Windows.""" - if blocking: - yield self.msvcrt.getch() - while self.msvcrt.kbhit(): - yield self.msvcrt.getch() - else: - def getchars(self, blocking=True): - """Get characters on Windows.""" + if blocking: + yield self.msvcrt.getch() + while self.msvcrt.kbhit(): + yield self.msvcrt.getch() - if blocking: - yield chr(self.msvcrt.getch()[0]) - while self.msvcrt.kbhit(): - yield chr(self.msvcrt.getch()[0]) class PlatformTest(Platform): KEYS = 'unix' From 594d404918133f010351dde6abdbd4420838e6ab Mon Sep 17 00:00:00 2001 From: Rupert Li Date: Wed, 21 Apr 2021 22:33:04 +0800 Subject: [PATCH 09/13] improve #2: better handling of the msvcrt.getch() problem in Windows+Python3 --- getkey/platforms.py | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/getkey/platforms.py b/getkey/platforms.py index 8db9b73..621983a 100644 --- a/getkey/platforms.py +++ b/getkey/platforms.py @@ -37,7 +37,10 @@ def __init__(self, keys=None, interrupts=None): def getkey(self, blocking=True): buffer = '' for c in self.getchars(blocking): - buffer += c + try: + buffer += c + except TypeError: + buffer += ''.join([chr(b) for b in c]) if buffer not in self.keys.escapes: break From 674cbb9a4925abf087f51badb640167f2268c23a Mon Sep 17 00:00:00 2001 From: Rupert Li Date: Wed, 21 Apr 2021 22:53:10 +0800 Subject: [PATCH 10/13] bugfix #3: does not capture Unicode chars under Windows (thank @malversan) --- getkey/platforms.py | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/getkey/platforms.py b/getkey/platforms.py index 621983a..fa6ea26 100644 --- a/getkey/platforms.py +++ b/getkey/platforms.py @@ -181,12 +181,17 @@ def __init__(self, keys=None, interrupts=None, msvcrt=None): def getchars(self, blocking=True): """Get characters on Windows.""" + def getchsequence(): + c = self.msvcrt.getwch() + # Iteration is needed to capture full escape sequences with msvcrt.getwch() + while c and c in self.keys.escapes: + c += self.msvcrt.getwch() + return c if blocking: - yield self.msvcrt.getch() + yield getchsequence() while self.msvcrt.kbhit(): - yield self.msvcrt.getch() - + yield getchsequence() class PlatformTest(Platform): KEYS = 'unix' From 25dd93e1ddb31fa64df3b65b2686bc53b2d20f9f Mon Sep 17 00:00:00 2001 From: Rupert Li Date: Wed, 21 Apr 2021 23:03:22 +0800 Subject: [PATCH 11/13] bugfix #4: output is messed after key capture in Linux (thank @malversan) --- getkey/platforms.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/getkey/platforms.py b/getkey/platforms.py index fa6ea26..f2a0597 100644 --- a/getkey/platforms.py +++ b/getkey/platforms.py @@ -116,7 +116,9 @@ def fileno(self): def context(self): fd = self.fileno() old_settings = self.termios.tcgetattr(fd) - self.tty.setcbreak(fd) + raw_settings = list(old_settings) + raw_settings[self.tty.LFLAG] = raw_settings[self.tty.LFLAG] & ~(self.termios.ECHO | self.termios.ICANON | self.termios.ISIG) + self.termios.tcsetattr(fd, self.termios.TCSADRAIN, raw_settings) try: yield finally: From 700d6c815b694277ed79996c0a11970ef04ef276 Mon Sep 17 00:00:00 2001 From: Rupert Li Date: Fri, 23 Apr 2021 23:24:20 +0800 Subject: [PATCH 12/13] revert 50a316bae4 and 68f2535d9a (I can't duplicate the problem any more) --- getkey/platforms.py | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/getkey/platforms.py b/getkey/platforms.py index f2a0597..28b41f9 100644 --- a/getkey/platforms.py +++ b/getkey/platforms.py @@ -131,8 +131,7 @@ def getchars(self, blocking=True): with self.context(): if blocking: yield self.__decoded_stream.read(1) - timeout = 0.08 - while self.select([self.fileno()], [], [], timeout)[0]: + while self.select([self.fileno()], [], [], 0)[0]: yield self.__decoded_stream.read(1) From 8aa95e733e5491934f80b2873aa955c435e1a327 Mon Sep 17 00:00:00 2001 From: Rupert Li Date: Sat, 24 Apr 2021 00:45:35 +0800 Subject: [PATCH 13/13] support SHIFT_F# on Windows --- getkey/keynames.py | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/getkey/keynames.py b/getkey/keynames.py index c5e986a..aa900e3 100644 --- a/getkey/keynames.py +++ b/getkey/keynames.py @@ -251,6 +251,19 @@ class WindowsKeys(object): HOME = '\xe0G' END = '\xe0O' + SHIFT_F1 = '\x00T' + SHIFT_F2 = '\x00U' + SHIFT_F3 = '\x00V' + SHIFT_F4 = '\x00W' + SHIFT_F5 = '\x00X' + SHIFT_F6 = '\x00Y' + SHIFT_F7 = '\x00Z' + SHIFT_F8 = '\x00[' + SHIFT_F9 = '\x00\\' + SHIFT_F10 = '\x00]' + SHIFT_F11 = '\xe0\x87' + SHIFT_F12 = '\xe0\x88' + CTRL_F1 = '\x00^' CTRL_F2 = '\x00_' CTRL_F3 = '\x00`'