Jump to content

Python: keyboard input WITHOUT block?

Go to solution Solved by Mr_KoKa,

@LightCode GamingIf you code on windows look for python msvcrt. On linux you would need to use select on sys.stdin to check if there is some data on standard input.

Same homework, different problem. 
I need a non-blocking way to get input (Input("") locks input until enter is hit) as to not block receiving messages.

 

Current code I have:

string = ""
while(cont):
    char = getch()
    print(char)
    if char != '\n' and char is not None:
        string = string+char
	else:
		#does it's thing with the string before reset
		string = ""

 

But it doesn't seem to grab the characters?

GIGABYTE Z97MX-G516GB DDR3 | I5 4690k @ 4.4ghz | 1TB SSHD, 500GB HDD, 128GB SSD | GTX 1070 8GB | Corsair Graphite 230 | EVGA 650W | Hyper 212 EVO

 

Cinebench R15: 636(all cores), 127FPS

 

Link to comment
https://linustechtips.com/topic/585993-python-keyboard-input-without-block/
Share on other sites

Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×