0

I'm trying to build a small Python program that reads the input from the user, but does not wait for the new line character.

working with Python 3.7

My requirements are:

  • Easy to run (No need for Sudo)

  • Can take every keyboard input (Including Fn or any available button)

  • Can work on OSX, Windows and Linux

  • Every keyboard input is received immediately

I took a look at several options, but every one of them had at least one requirement it did not fulfill:

Any suggestion would be highly appreciated

boaz
  • 920
  • 1
  • 13
  • 32
  • Are you looking for "a small Python program" just to read one keypress, or for a library/module, or for code? The first is overkill, the second is off-topic for this site, and the third seems unlikely to be do-able in relatively few lines given all your requirements (especially working in three different operating systems). Also, do you want the kepresses in a buffer or just a note if the key is currently pressed? Do you want key releases to be noted? – Rory Daulton Jul 15 '18 at 19:16
  • @RoryDaulton - Option 3 is what I aim at.I don't mind writing a lot of code for this. I would like to get it without a buffer, every key press. And as a start, lets say I don't care about key releases, only key press (Which ever option that makes it easier) – boaz Jul 16 '18 at 04:51

1 Answers1

0

for command line arguments maybe module argparse (e.g. you can control command line arguments for your scripts): https://docs.python.org/3/library/argparse.html

and for key events maybe pynput will be useful for you (problably without sudo (except MacOS)): https://pypi.org/project/pynput/ or use TkInter or PyGames

xyz
  • 306
  • 3
  • 11
  • I need to get the input while the program is running, I don't have it as an input when starting it. How would argparse solve this? I've looked at pynput, but due to the sudo on MacOS, it won't work for me – boaz Jul 16 '18 at 04:55
  • I think TkInter might be a good solution for me. Lets me try it later toady. Will update later today – boaz Jul 16 '18 at 06:44