Giter Site home page Giter Site logo

getkey's People

Contributors

boxed avatar brbsix avatar kcsaff avatar magmax avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

getkey's Issues

Error on Windows

> python
Python 3.6.2 (v3.6.2:5fd33b5, Jul  8 2017, 04:57:36) [MSC v.1900 64 bit (AMD64)] on win32
Type "help", "copyright", "credits" or "license" for more information.
>>> import getkey
>>> getkey.getkey()
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "F:\PortableApps\Python\lib\site-packages\getkey\platforms.py", line 40, in getkey
    buffer += c
TypeError: must be str, not bytes

Error while composing docker images: Error initializing standard platform: Cannot use unix platform on non-file-like stream

Complete output from command python setup.py egg_info:
Error initializing standard platform: Cannot use unix platform on non-file-like stream
/usr/lib/python2.7/distutils/dist.py:267: UserWarning: Unknown distribution option: 'python_requires'
  warnings.warn(msg)
warning: no previously-included files matching '*.pyc' found anywhere in distribution
no previously-included directories found matching 'docs/build/'
zip_safe flag not set; analyzing archive contents...

CANT INSTALL!!!!

ERROR: ERROR: Command errored out with exit status 1: command: 'c:\users\mark7\appdata\local\programs\python\python38\python.exe' -c 'import sys, setuptools, tokenize; sys.argv[0] = '"'"'C:\\Users\\mark7\\AppData\\Local\\Temp\\pip-install-y5yz3fjh\\getkey\\setup.py'"'"'; __file__='"'"'C:\\Users\\mark7\\AppData\\Local\\Temp\\pip-install-y5yz3fjh\\getkey\\setup.py'"'"';f=getattr(tokenize, '"'"'open'"'"', open)(__file__);code=f.read().replace('"'"'\r\n'"'"', '"'"'\n'"'"');f.close();exec(compile(code, __file__, '"'"'exec'"'"'))' egg_info --egg-base 'C:\Users\mark7\AppData\Local\Temp\pip-pip-egg-info-29ojwb12' cwd: C:\Users\mark7\AppData\Local\Temp\pip-install-y5yz3fjh\getkey\ Complete output (9 lines): Traceback (most recent call last): File "<string>", line 1, in <module> File "C:\Users\mark7\AppData\Local\Temp\pip-install-y5yz3fjh\getkey\setup.py", line 37, in <module> long_description=read_description(), File "C:\Users\mark7\AppData\Local\Temp\pip-install-y5yz3fjh\getkey\setup.py", line 11, in read_description return fd.read() File "c:\users\mark7\appdata\local\programs\python\python38\lib\encodings\cp1252.py", line 23, in decode return codecs.charmap_decode(input,self.errors,decoding_table)[0] UnicodeDecodeError: 'charmap' codec can't decode byte 0x81 in position 876: character maps to <undefined> ---------------------------------------- ERROR: Command errored out with exit status 1: python setup.py egg_info Check the logs for full command output.

Waits for enter key to be pressed

I have a script automatically detecting the pressed key and printing it but nothing gets printed until the enter key gets pressed

from getkey import getkey, keys

while True:
key = getkey()
print(key, end='')

edit: The problem only occurs when the print function has the end= part

Distinguish numpad buttons

Example: I want to have information if the key which was pressed is KEYPAD 5 or 5.
For now it seems that Keypad 5 is interpreted as "5" when using getkey() method.
If there a way to distinguish numpad buttons and normal one?

Error installing on Windows

> pip install getkey
Collecting getkey
  Using cached getkey-0.6.5.tar.gz
    Complete output from command python setup.py egg_info:
    Traceback (most recent call last):
      File "<string>", line 1, in <module>
      File "F:\PortableApps\ConEmu\Data\Temp\pip-build-tztu7ucg\getkey\setup.py", line 37, in <module>
        long_description=read_description(),
      File "F:\PortableApps\ConEmu\Data\Temp\pip-build-tztu7ucg\getkey\setup.py", line 11, in read_description
        return fd.read()
      File "c:\data\flash drive\portableapps\python\lib\encodings\cp1252.py", line 23, in decode
        return codecs.charmap_decode(input,self.errors,decoding_table)[0]
    UnicodeDecodeError: 'charmap' codec can't decode byte 0x81 in position 876: character maps to <undefined>

    ----------------------------------------
Command "python setup.py egg_info" failed with error code 1 in F:\PortableApps\ConEmu\Data\Temp\pip-build-tztu7ucg\getkey\

[bug]: trouble installing getkey

After I enter pip install getkey, it returns the following error:

Collecting getkey
  Using cached getkey-0.6.5.tar.gz (13 kB)
  Preparing metadata (setup.py) ... error
  error: subprocess-exited-with-error

  × python setup.py egg_info did not run successfully.
  │ exit code: 1
  ╰─> [10 lines of output]
      Traceback (most recent call last):
        File "<string>", line 2, in <module>
        File "<pip-setuptools-caller>", line 34, in <module>
        File "C:\Users\aaron\AppData\Local\Temp\pip-install-p1wko10r\getkey_65db5911d39c456cb3e7fe07fbcc605c\setup.py", line 37, in <module>
          long_description=read_description(),
        File "C:\Users\aaron\AppData\Local\Temp\pip-install-p1wko10r\getkey_65db5911d39c456cb3e7fe07fbcc605c\setup.py", line 11, in read_description
          return fd.read()
        File "C:\Program Files\WindowsApps\PythonSoftwareFoundation.Python.3.9_3.9.3568.0_x64__qbz5n2kfra8p0\lib\encodings\cp1252.py", line 23, in decode
          return codecs.charmap_decode(input,self.errors,decoding_table)[0]
      UnicodeDecodeError: 'charmap' codec can't decode byte 0x81 in position 876: character maps to <undefined>
      [end of output]

Maybe some time can be spared for the bug to be fixed 😄

Does not capture Unicode chars under Windows

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

PIP will not install getkey

Here is the error...

`Microsoft Windows [Version 10.0.18363.778]
(c) 2019 Microsoft Corporation. All rights reserved.

C:\Users\Toolman>pip install getkey
WARNING: pip is being invoked by an old script wrapper. This will fail in a future version of pip.
Please see pypa/pip#5599 for advice on fixing the underlying issue.
To avoid this problem you can invoke Python with '-m pip' instead of running pip directly.
Defaulting to user installation because normal site-packages is not writeable
Collecting getkey
Using cached getkey-0.6.5.tar.gz (13 kB)
ERROR: Command errored out with exit status 1:
command: 'c:\program files\python36\python.exe' -c 'import sys, setuptools, tokenize; sys.argv[0] = '"'"'C:\Users\Toolman\AppData\Local\Temp\pip-install-22de4zht\getkey\setup.py'"'"'; file='"'"'C:\Users\Toolman\AppData\Local\Temp\pip-install-22de4zht\getkey\setup.py'"'"';f=getattr(tokenize, '"'"'open'"'"', open)(file);code=f.read().replace('"'"'\r\n'"'"', '"'"'\n'"'"');f.close();exec(compile(code, file, '"'"'exec'"'"'))' egg_info --egg-base 'C:\Users\Toolman\AppData\Local\Temp\pip-pip-egg-info-neweuhzn'
cwd: C:\Users\Toolman\AppData\Local\Temp\pip-install-22de4zht\getkey
Complete output (9 lines):
Traceback (most recent call last):
File "", line 1, in
File "C:\Users\Toolman\AppData\Local\Temp\pip-install-22de4zht\getkey\setup.py", line 37, in
long_description=read_description(),
File "C:\Users\Toolman\AppData\Local\Temp\pip-install-22de4zht\getkey\setup.py", line 11, in read_description
return fd.read()
File "c:\program files\python36\lib\encodings\cp1252.py", line 23, in decode
return codecs.charmap_decode(input,self.errors,decoding_table)[0]
UnicodeDecodeError: 'charmap' codec can't decode byte 0x81 in position 876: character maps to
----------------------------------------
ERROR: Command errored out with exit status 1: python setup.py egg_info Check the logs for full command output.`

Output is messed after key capture in Linux

Using tty.setcbreak() messes output after key capture, leaving console echo permanently deactivated onwards.

This can be avoided by touching only the necessary tty terminal flags instead of calling tty.setbreak().

So in PlatformUnix.context(), instead of doing this:

        old_settings = self.termios.tcgetattr(fd)
        self.tty.setcbreak(fd)

this works better and without unwanted effects:

        old_settings = self.termios.tcgetattr(fd)
        raw_settings = old_settings.copy()
        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)

Tested in:
Ubuntu 16.04
Python 3.5.2

Error installing on mac same error as window...

pip install getkey                                                                                                  (master✱) 
DEPRECATION: Python 2.7 will reach the end of its life on January 1st, 2020. Please upgrade your Python as Python 2.7 won't be maintained after that date. A future version of pip will drop support for Python 2.7.
Collecting getkey
  Using cached https://files.pythonhosted.org/packages/74/f2/3312ea94369f410967667eeca61d261cdf3037df6ea827078ac7c5321150/getkey-0.6.5.tar.gz
    Complete output from command python setup.py egg_info:
    Error initializing standard platform: Cannot use unix platform on non-file-like stream
    /System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/distutils/dist.py:267: UserWarning: Unknown distribution option: 'python_requires'
      warnings.warn(msg)
    warning: no previously-included files matching '*.pyc' found anywhere in distribution
    no previously-included directories found matching 'docs/build/'
    zip_safe flag not set; analyzing archive contents...
    
    Installed /private/var/folders/k4/dh9kh38j6pxgc5x_xzvgcr6w0000gn/T/pip-install-xWGFt3/getkey/.eggs/flake8-3.7.2-py2.7.egg
    Searching for typing
    Reading https://pypi.python.org/simple/typing/
    Best match: typing 3.6.6
    Downloading https://files.pythonhosted.org/packages/bf/9b/2bf84e841575b633d8d91ad923e198a415e3901f228715524689495b4317/typing-3.6.6.tar.gz#sha256=4027c5f6127a6267a435201981ba156de91ad0d1d98e9ddc2aa173453453492d
    Processing typing-3.6.6.tar.gz
    Writing /var/folders/k4/dh9kh38j6pxgc5x_xzvgcr6w0000gn/T/easy_install-6_E7iH/typing-3.6.6/setup.cfg
    Running typing-3.6.6/setup.py -q bdist_egg --dist-dir /var/folders/k4/dh9kh38j6pxgc5x_xzvgcr6w0000gn/T/easy_install-6_E7iH/typing-3.6.6/egg-dist-tmp-llVr7a
    zip_safe flag not set; analyzing archive contents...
    Copying typing-3.6.6-py2.7.egg to /private/var/folders/k4/dh9kh38j6pxgc5x_xzvgcr6w0000gn/T/pip-install-xWGFt3/getkey/.eggs
    
    Installed /private/var/folders/k4/dh9kh38j6pxgc5x_xzvgcr6w0000gn/T/pip-install-xWGFt3/getkey/.eggs/typing-3.6.6-py2.7.egg
    Searching for enum34
    Reading https://pypi.python.org/simple/enum34/
    Best match: enum34 1.1.6
    Downloading https://files.pythonhosted.org/packages/e8/26/a6101edcf724453845c850281b96b89a10dac6bd98edebc82634fccce6a5/enum34-1.1.6.zip#sha256=2d81cbbe0e73112bdfe6ef8576f2238f2ba27dd0d55752a776c41d38b7da2850
    Processing enum34-1.1.6.zip
    Writing /var/folders/k4/dh9kh38j6pxgc5x_xzvgcr6w0000gn/T/easy_install-FKns0M/enum34-1.1.6/setup.cfg
    Running enum34-1.1.6/setup.py -q bdist_egg --dist-dir /var/folders/k4/dh9kh38j6pxgc5x_xzvgcr6w0000gn/T/easy_install-FKns0M/enum34-1.1.6/egg-dist-tmp-ezxl7L
    zip_safe flag not set; analyzing archive contents...
    Copying enum34-1.1.6-py2.7.egg to /private/var/folders/k4/dh9kh38j6pxgc5x_xzvgcr6w0000gn/T/pip-install-xWGFt3/getkey/.eggs
    
    Installed /private/var/folders/k4/dh9kh38j6pxgc5x_xzvgcr6w0000gn/T/pip-install-xWGFt3/getkey/.eggs/enum34-1.1.6-py2.7.egg
    Searching for configparser
    Reading https://pypi.python.org/simple/configparser/
    Best match: configparser 3.7.1
    Downloading https://files.pythonhosted.org/packages/b6/a6/eceea7c5a5dbcf56815bed411c38cabd8a879386be10717b160e7362b5a2/configparser-3.7.1.tar.gz#sha256=5bd5fa2a491dc3cfe920a3f2a107510d65eceae10e9c6e547b90261a4710df32
    Processing configparser-3.7.1.tar.gz
    Writing /var/folders/k4/dh9kh38j6pxgc5x_xzvgcr6w0000gn/T/easy_install-DMFHE4/configparser-3.7.1/setup.cfg
    Running configparser-3.7.1/setup.py -q bdist_egg --dist-dir /var/folders/k4/dh9kh38j6pxgc5x_xzvgcr6w0000gn/T/easy_install-DMFHE4/configparser-3.7.1/egg-dist-tmp-3L5E49
    zip_safe flag not set; analyzing archive contents...
    backports.__init__: module references __path__
    creating /private/var/folders/k4/dh9kh38j6pxgc5x_xzvgcr6w0000gn/T/pip-install-xWGFt3/getkey/.eggs/UNKNOWN-0.0.0-py2.7.egg
    Extracting UNKNOWN-0.0.0-py2.7.egg to /private/var/folders/k4/dh9kh38j6pxgc5x_xzvgcr6w0000gn/T/pip-install-xWGFt3/getkey/.eggs
    
    Installed /private/var/folders/k4/dh9kh38j6pxgc5x_xzvgcr6w0000gn/T/pip-install-xWGFt3/getkey/.eggs/UNKNOWN-0.0.0-py2.7.egg
    Traceback (most recent call last):
      File "<string>", line 1, in <module>
      File "/private/var/folders/k4/dh9kh38j6pxgc5x_xzvgcr6w0000gn/T/pip-install-xWGFt3/getkey/setup.py", line 74, in <module>
        'flake8',
      File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/distutils/core.py", line 111, in setup
        _setup_distribution = dist = klass(attrs)
      File "/System/Library/Frameworks/Python.framework/Versions/2.7/Extras/lib/python/setuptools/dist.py", line 268, in __init__
        self.fetch_build_eggs(attrs['setup_requires'])
      File "/System/Library/Frameworks/Python.framework/Versions/2.7/Extras/lib/python/setuptools/dist.py", line 313, in fetch_build_eggs
        replace_conflicting=True,
      File "/System/Library/Frameworks/Python.framework/Versions/2.7/Extras/lib/python/pkg_resources/__init__.py", line 846, in resolve
        raise DistributionNotFound(req, requirers)
    pkg_resources.DistributionNotFound: The 'configparser' distribution was not found and is required by flake8

Bug while installing

Whenever i use pip install getkey i get this error:

Collecting getkey
  Using cached getkey-0.6.5.tar.gz (13 kB)
  Installing build dependencies ... done
  Getting requirements to build wheel ... error
  error: subprocess-exited-with-error

  × Getting requirements to build wheel did not run successfully.
  │ exit code: 1
  ╰─> [25 lines of output]
      Traceback (most recent call last):
        File "C:\Users\jusse\AppData\Local\Programs\Python\Python311\Lib\site-packages\pip\_vendor\pyproject_hooks\_in_process\_in_process.py", line 353, in <module>
          main()
        File "C:\Users\jusse\AppData\Local\Programs\Python\Python311\Lib\site-packages\pip\_vendor\pyproject_hooks\_in_process\_in_process.py", line 335, in main
          json_out['return_val'] = hook(**hook_input['kwargs'])
                                   ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
        File "C:\Users\jusse\AppData\Local\Programs\Python\Python311\Lib\site-packages\pip\_vendor\pyproject_hooks\_in_process\_in_process.py", line 118, in get_requires_for_build_wheel
          return hook(config_settings)
                 ^^^^^^^^^^^^^^^^^^^^^
        File "C:\Users\jusse\AppData\Local\Temp\pip-build-env-nef3dnt8\overlay\Lib\site-packages\setuptools\build_meta.py", line 338, in get_requires_for_build_wheel
          return self._get_build_requires(config_settings, requirements=['wheel'])
                 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
        File "C:\Users\jusse\AppData\Local\Temp\pip-build-env-nef3dnt8\overlay\Lib\site-packages\setuptools\build_meta.py", line 320, in _get_build_requires
          self.run_setup()
        File "C:\Users\jusse\AppData\Local\Temp\pip-build-env-nef3dnt8\overlay\Lib\site-packages\setuptools\build_meta.py", line 485, in run_setup
          self).run_setup(setup_script=setup_script)
                ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
        File "C:\Users\jusse\AppData\Local\Temp\pip-build-env-nef3dnt8\overlay\Lib\site-packages\setuptools\build_meta.py", line 335, in run_setup
          exec(code, locals())
        File "<string>", line 37, in <module>
        File "<string>", line 11, in read_description
        File "C:\Users\jusse\AppData\Local\Programs\Python\Python311\Lib\encodings\cp1252.py", line 23, in decode
          return codecs.charmap_decode(input,self.errors,decoding_table)[0]
                 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
      UnicodeDecodeError: 'charmap' codec can't decode byte 0x81 in position 876: character maps to <undefined>
      [end of output]

  note: This error originates from a subprocess, and is likely not a problem with pip.
error: subprocess-exited-with-error

× Getting requirements to build wheel did not run successfully.
│ exit code: 1
╰─> See above for output.

note: This error originates from a subprocess, and is likely not a problem with pip.

Installing Error: UnicodeDecodeError: 'charmap' codec can't decode byte 0x81 in position 876: character maps to <undefined>

Microsoft Windows [Version 10.0.22000.1098]
(c) Microsoft Corporation. All rights reserved.

C:\Users\Max>pip install getkey
Collecting getkey
  Downloading getkey-0.6.5.tar.gz (13 kB)
  Preparing metadata (setup.py) ... error
  error: subprocess-exited-with-error

  × python setup.py egg_info did not run successfully.
  │ exit code: 1
  ╰─> [10 lines of output]
      Traceback (most recent call last):
        File "<string>", line 2, in <module>
        File "<pip-setuptools-caller>", line 34, in <module>
        File "C:\Users\Max\AppData\Local\Temp\pip-install-anlunwwx\getkey_fc49247753c54fa9a34fc77cf4f4a9d3\setup.py", line 37, in <module>
          long_description=read_description(),
        File "C:\Users\Max\AppData\Local\Temp\pip-install-anlunwwx\getkey_fc49247753c54fa9a34fc77cf4f4a9d3\setup.py", line 11, in read_description
          return fd.read()
        File "C:\Users\Max\AppData\Local\Programs\Python\Python310\lib\encodings\cp1252.py", line 23, in decode
          return codecs.charmap_decode(input,self.errors,decoding_table)[0]
      UnicodeDecodeError: 'charmap' codec can't decode byte 0x81 in position 876: character maps to <undefined>
      [end of output]

  note: This error originates from a subprocess, and is likely not a problem with pip.
error: metadata-generation-failed

× Encountered error while generating package metadata.
╰─> See above for output.

note: This is an issue with the package mentioned above, not pip.
hint: See above for details.

C:\Users\Max>pip install getkey
Collecting getkey
  Using cached getkey-0.6.5.tar.gz (13 kB)
  Preparing metadata (setup.py) ... error
  error: subprocess-exited-with-error

  × python setup.py egg_info did not run successfully.
  │ exit code: 1
  ╰─> [10 lines of output]
      Traceback (most recent call last):
        File "<string>", line 2, in <module>
        File "<pip-setuptools-caller>", line 34, in <module>
        File "C:\Users\Max\AppData\Local\Temp\pip-install-p6mi5z9k\getkey_6404c92d3cd2405c851ac2445dbdf64b\setup.py", line 37, in <module>
          long_description=read_description(),
        File "C:\Users\Max\AppData\Local\Temp\pip-install-p6mi5z9k\getkey_6404c92d3cd2405c851ac2445dbdf64b\setup.py", line 11, in read_description
          return fd.read()
        File "C:\Users\Max\AppData\Local\Programs\Python\Python310\lib\encodings\cp1252.py", line 23, in decode
          return codecs.charmap_decode(input,self.errors,decoding_table)[0]
      UnicodeDecodeError: 'charmap' codec can't decode byte 0x81 in position 876: character maps to <undefined>
      [end of output]

  note: This error originates from a subprocess, and is likely not a problem with pip.
error: metadata-generation-failed

× Encountered error while generating package metadata.
╰─> See above for output.

note: This is an issue with the package mentioned above, not pip.
hint: See above for details.

Doesn't work well when started from IDLE

When the program is started from command line (on Windows 10 + Python 2.7) everything works fine but if it is started from IDLE getkey() always (even if nothing is pressed) returns this character: ˙. This was my test code:

from getkey import getkey, keys
from time import sleep
sleep(2)
print "Start"
key = getkey(blocking=True)
while key != "m":
    if key == keys.UP:
        print "UP"
    else:
        print key
    sleep(2)
    print "Next..."
    key = getkey(blocking=True)
print "End"

BTW, is it possible to prevent buffering of pressed keys when using non-blocking call like key = getkey(blocking=False)? I'd like to detect only if the key is pressed in the moment of execution of the getkey(), but all the keys pressed during the sleep() are detected one by one as well.

Does not work on Windows with Python 3: TypeError

Under Windows the msvcrt.getch() call returns bytes, not chars. In Python 3 both types are not compatible, so concatenating the result to a string fails with a TypeError.

This code in Platform.getkey() throws TypeError exception ALWAYS in Windows:

        buffer = ''
        for c in self.getchars(blocking):
            buffer += c
            ...

I have ammended it to work by allowing the platform classes to return bytes instead of chars:

        buffer = ''
        for c in self.getchars(blocking):
            try:
                buffer += c
            except TypeError:
                buffer += ''.join([chr(b) for b in c])
            ...

This supports any platform that captures chars, multichars, bytes or multibytes. And also complies with the Python philosophy of trying instead of checking.

Tested in:
Windows 8.1
Python 3.6.1

Calling getkey(blocking=False) results in missed keyboard inputs

Using getkey==0.6.5 on Fedora 31.

$ uname -a
Linux localhost.localdomain 5.8.16-100.fc31.x86_64 #1 SMP Mon Oct 19 14:16:07 UTC 2020 x86_64 x86_64 x86_64 GNU/Linux

$ python --version
Python 3.7.9

I have this small program:

from getkey import getkey
import time

for i in range(10):
    time.sleep(0.5)
    print("READ: {}".format(getkey(blocking=False)))

When I run it and type some random input on my keyboard (for example "asdf") I would expect the result to be something similar to the following:

$ python program.py 
asdf
READ: a
READ: s
READ: d
READ: f

But instead I get nothing. Meaning that my input is not printed back to me.

$ python program.py 
asdf
READ:
READ:
READ:
READ:

I suspect that this happens because, when tty.setcbreak is called to make all inputs immediately available for reading on UNIX platforms, the when argument is not passed so its default value of termios.TCSAFLUSH is used. This means that the cbreak property will be in effect after transmitting all queued output and discarding all queued input which may not happen immediately so some inputs will be lost.

References: https://docs.python.org/3/library/tty.html and https://docs.python.org/3/library/termios.html#termios.tcsetattr

Bug in keys declaration

Currently there is at least a wrong key declaration at keynames.py:
CTRL_ALT_EQUALS = '\x00x83'

Should be:
CTRL_ALT_EQUALS = '\x00\x83'

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.