getch
Opened this issue · 1 comments
ilfirin-ms commented
I am baffled, I cannot find simple getch() one key input. I have to build application, layout, keybindings, output, full screen ...
Could it be done simpler?
Thank you
jonathanslenders commented
In case anyone comes across this, we have an example in the docs: https://python-prompt-toolkit.readthedocs.io/en/stable/pages/asking_for_input.html#reading-keys-from-stdin-one-key-at-a-time-but-without-a-prompt
import asyncio
from prompt_toolkit.input import create_input
from prompt_toolkit.keys import Keys
async def main() -> None:
done = asyncio.Event()
input = create_input()
def keys_ready():
for key_press in input.read_keys():
print(key_press)
if key_press.key == Keys.ControlC:
done.set()
with input.raw_mode():
with input.attach(keys_ready):
await done.wait()
if __name__ == "__main__":
asyncio.run(main())However, we don't have a higher level helper yet to simplify things. (This was not really what prompt_toolkit was designed for.)