Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion getkey/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,4 +14,4 @@
key = keys # alias
bang = __platform.bang

__version__ = '0.6.5'
__version__ = '0.6.6'
19 changes: 16 additions & 3 deletions getkey/keynames.py
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand Down Expand Up @@ -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`'
Expand Down Expand Up @@ -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'
Expand Down
20 changes: 15 additions & 5 deletions getkey/platforms.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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:
Expand Down Expand Up @@ -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'
Expand Down
4 changes: 2 additions & 2 deletions requirements-dev.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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
wheel >= 0.24.0
3 changes: 2 additions & 1 deletion setup.py
Original file line number Diff line number Diff line change
@@ -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()


Expand Down