After discussing this issue on github with the creator of the project - magmax (here), I understood that readchar package works only if you try to run it from a terminal but not from any IDE or other non terminal executions. The error is caused because it tries to get the terminal settings which is non existent in this case.

I have been trying to run it from an Wing IDE. The program works great if you try to run it from a terminal.

P.S: magmax suggested to use readchar.keys.ENTER instead of \r . And suggested to have a look at https://github.com/magmax/python-inquirer & its examples

Answer from inblueswithu on Stack Overflow
🌐
PyPI
pypi.org › project › readchar
readchar · PyPI
Download URL: readchar-4.2.2-py3-none-any.whl · Upload date: Apr 6, 2026 · Size: 9.4 kB · Tags: Python 3 · Uploaded using Trusted Publishing? No · Uploaded via: twine/6.2.0 CPython/3.14.3 · See more details on using hashes here. Supported by ·
      » pip install readchar
    
Published   Apr 06, 2026
Version   4.2.2
🌐
GitHub
github.com › magmax › python-readchar
GitHub - magmax/python-readchar: Python library to read characters and key strokes · GitHub
Born as a python-inquirer requirement. ... Or download the source code from PyPi. ... from readchar import readkey, key while True: k = readkey() if k == "a": # do stuff if k == key.DOWN: # do stuff if k == key.ENTER: break
Starred by 176 users
Forked by 52 users
Languages   Python 99.1% | Makefile 0.9%
🌐
ProgramCreek
programcreek.com › python › example › 127667 › readchar.readkey
Python Examples of readchar.readkey
def select( options: List[str], selected_index: int = 0) -> int: print('\n' * (len(options) - 1)) while True: print(f'\033[{len(options) + 1}A') for i, option in enumerate(options): print('\033[K{}{}'.format( '\033[1m[\033[32;1m x \033[0;1m]\033[0m ' if i == selected_index else '\033[1m[ ]\033[0m ...
🌐
Snyk
snyk.io › advisor › readchar › functions › readchar.readkey
https://snyk.io/advisor/python/readchar/functions/...
#Only for Python 2.7 #Very Important!!!!!!!!! import readchar while True: key = readchar.readkey() if key == "w": print("up") elif key == "s": print("down") elif key == "a": print("left") elif key == "d": print("right") elif key == "z": print("exiting") break
🌐
HotExamples
python.hotexamples.com › examples › readchar › - › readkey › python-readkey-function-examples.html
Python readkey Examples, readchar.readkey Python Examples - HotExamples
You can rate examples to help us improve the quality of examples. ... def friendmactch(friend): special_list=[] counter= 0 for person in friends: checker = frndct.get(person, None) if checker is None and person !=friend: print friend print person print "Do they know each other?\n Press the right arrow key if they are connected. Press the left arrow key if they are not connected\n" satisfaction = "no_satisfaction" while satisfaction == "no_satisfaction": response = readchar.readkey() print response if response == "\x1b[C": special_list.append(person) print '\n\n' response = 0 satisfaction = "satisfaction" elif response == "\x1b[D": print '\n' response = 0 satisfaction = "satisfaction" elif person !=friend: counter +=1 return special_list
🌐
HotExamples
python.hotexamples.com › examples › readchar › - › readchar › python-readchar-function-examples.html
Python readchar Examples, readchar.readchar Python Examples - HotExamples
def countNumberUPTO(): total_number = 0 total_other = 0 inputs = [] # crio a list de imputs while True: print ("intreduza carater:") intVariavel = readchar.readchar() inputs.append(intVariavel) # acrecenta varaiveis no input # retiri o isnumeric pois so dava para python3 e nao tinha conseguido fazer isso anteriormente intVariavel = ord(intVariavel) if intVariavel != 120: print ("intreduza o valor outra vez :") else: break # para destingir se e numero ou nao for input in inputs: # vai correndo as variaveis que tenho nas listas if input.isdigit(): total_other = total_number + 1 else: total_numbe
🌐
Snyk
snyk.io › advisor › readchar › functions › readchar.readchar
How to use the readchar.readchar function in readchar | Snyk
[Yn] ') action = readchar.readchar() if action == '': exit(1) if action not in ('Y', 'y', '\r', '\n'): stats['user_skipped_retag'] += 1 continue stats['retag'] += 1 elif not args.retag_changed: stats['no_retag'] += 1 continue else: stats['retag'] += 1 else: stats['new_tag'] += 1 updates.append((t, new_transactions)) if args.num_updates > 0:
🌐
Pydigger
pydigger.com › pypi › readchar
readchar
September 11, 2022 - [![GitHub Repository](https://img.shields.io/badge/-GitHub-#0D0D0D?logo=github&labelColor=gray)](https://github.com/magmax/python-readchar) [![Latest PyPi version](https://img.shields.io/pypi/v/readchar.svg)](https://pypi.python.org/pypi/readchar) [![supported Python versions](https://img....
Find elsewhere
🌐
GitHub
github.com › trinketapp › python-readchar
GitHub - trinketapp/python-readchar: Python library to read characters and key strokes
Born as a python-inquirer requirement. The idea is to have a portable way to read single characters and key-strokes. ... The readchar library is compatible with python 2.6, 2.7, 3.3, 3.4 and 3.5.
Author   trinketapp
🌐
GeeksforGeeks
geeksforgeeks.org › python-program-to-read-character-by-character-from-a-file
Python program to read character by character from a file - GeeksforGeeks
September 6, 2024 - Python is a great language for file handling, and it provides built-in functions to make reading files easy with which we can read file character by character. In this article, we will cover a few examples of it.
🌐
GitHub
github.com › magmax › python-readchar › blob › master › readchar › _posix_key.py
python-readchar/readchar/_posix_key.py at master · magmax/python-readchar
Python library to read characters and key strokes. Contribute to magmax/python-readchar development by creating an account on GitHub.
Author   magmax
Top answer
1 of 16
244

Here's a link to the ActiveState Recipes site that says how you can read a single character in Windows, Linux and OSX:

    getch()-like unbuffered character reading from stdin on both Windows and Unix

class _Getch:
    """Gets a single character from standard input.  Does not echo to the
screen."""
    def __init__(self):
        try:
            self.impl = _GetchWindows()
        except ImportError:
            self.impl = _GetchUnix()

    def __call__(self): return self.impl()


class _GetchUnix:
    def __init__(self):
        import tty, sys

    def __call__(self):
        import sys, tty, termios
        fd = sys.stdin.fileno()
        old_settings = termios.tcgetattr(fd)
        try:
            tty.setraw(sys.stdin.fileno())
            ch = sys.stdin.read(1)
        finally:
            termios.tcsetattr(fd, termios.TCSADRAIN, old_settings)
        return ch


class _GetchWindows:
    def __init__(self):
        import msvcrt

    def __call__(self):
        import msvcrt
        return msvcrt.getch()


getch = _Getch()
2 of 16
97
sys.stdin.read(1)

will basically read 1 byte from STDIN.

If you must use the method which does not wait for the \n you can use this code as suggested in previous answer:

class _Getch:
    """Gets a single character from standard input.  Does not echo to the screen."""
    def __init__(self):
        try:
            self.impl = _GetchWindows()
        except ImportError:
            self.impl = _GetchUnix()

    def __call__(self): return self.impl()


class _GetchUnix:
    def __init__(self):
        import tty, sys

    def __call__(self):
        import sys, tty, termios
        fd = sys.stdin.fileno()
        old_settings = termios.tcgetattr(fd)
        try:
            tty.setraw(sys.stdin.fileno())
            ch = sys.stdin.read(1)
        finally:
            termios.tcsetattr(fd, termios.TCSADRAIN, old_settings)
        return ch


class _GetchWindows:
    def __init__(self):
        import msvcrt

    def __call__(self):
        import msvcrt
        return msvcrt.getch()


getch = _Getch()

(taken from http://code.activestate.com/recipes/134892/)

🌐
Readthedocs
learn-pylib.readthedocs.io › readchar › index.html
readchar - Read keyboard events - learn_pylib 0.1.1 documentation
如果最新一次的丢筛子过了 3 秒成功结束, 而用户期间没有按下任意字母键, 11则会打印出用户按下的数字以及丢出的结果. 12""" 13 14import typing as T 15import random 16import multiprocessing 17 18import readchar 19 20 21def toss(key: str) -> T.Optional[T.Tuple[str, int]]: 22 """ 23 The real long-running job.
🌐
GitHub
github.com › magmax › python-readchar › blob › master › README.md
python-readchar/README.md at master · magmax/python-readchar
Born as a python-inquirer requirement. ... Or download the source code from PyPi. ... from readchar import readkey, key while True: k = readkey() if k == "a": # do stuff if k == key.DOWN: # do stuff if k == key.ENTER: break
Author   magmax
🌐
Snyk
snyk.io › advisor › readchar › readchar code examples
Top 5 readchar Code Examples | Snyk
readchar code examples View all readchar analysis · Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately. Enable here · magmax / python-inquirer / tests / integration / test_console_render.py View on Github ·
🌐
Synthiam
synthiam.com › docs › python api › file › readchar
readChar - File - Python API - Support - Synthiam
November 30, 2023 - File.readChar(filename) The character at the current read position of the file.
🌐
PyPI
pypi.org › project › readchar › 0.7
readchar 0.7
JavaScript is disabled in your browser · Please enable JavaScript to proceed · A required part of this site couldn’t load. This may be due to a browser extension, network issues, or browser settings. Please check your connection, disable any ad blockers, or try using a different browser
🌐
Shallow Thoughts
shallowsky.com › blog › programming › python-read-characters.html
Reading keypresses in Python (Shallow Thoughts)
A less minimal example: keyreader.py, a class to read characters, with blocking and echo optional. It also cleans up after itself on exit, though most of the time that seems to happen automatically when I exit the Python script.