Skip to content

Does not capture Unicode chars under Windows #11

Description

@malversan

Currently in Windows the capture is made using msvcrt.getch(), which only captures one-byte at a time. This dramatically reduces the amount of characters that can be captured (along with producing bytes instead of chars, see issue #10).

Using msvcrt.getwch() instead produces multibyte captures and also returns chars instead of bytes.

So the code in PlatformWindows.getchars():

	def getchars(self, blocking=True):
		"""Get characters on Windows."""
		if blocking:
			yield self.msvcrt.getch()
		while self.msvcrt.kbhit():
			yield self.msvcrt.getch()

should be substituted with this:

	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 getchsequence()
		while self.msvcrt.kbhit():
			yield getchsequence()

Tested in:
Windows 8.1, Python 3.6.1

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions