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/keynames.py b/getkey/keynames.py index 51b885b..aa900e3 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' @@ -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`' @@ -313,7 +326,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' diff --git a/getkey/platforms.py b/getkey/platforms.py index 3bb4345..28b41f9 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 @@ -113,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: @@ -177,12 +182,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' 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 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()