I am doing code to read a key is pressed.
The KEYBOARD module is works but it will read keys even I use another window-box which I do not want.
I looked up online and seem off my points, they talk about wait for ENTER key and they keep talk about KEYBOARD.
I am looking for to read a key when key is pressed and get the value with in same the window-box.
Any idea?
Please show your code so far (please use
bbcode tags)
Difficult to advise otherwise.
(Feb-19-2023, 02:04 PM)Larz60+ Wrote: [ -> ]Please show your code so far (please use bbcode tags)
Difficult to advise otherwise.
import keyboard
loopstop=1
while loopstop:
keypress = keyboard.read_key()
if keypress != 0:
print(keypress)
if keypress == "esc":
loopstop=0
This code what i have problem is it will read the key anywhere in OS like I use CMD and it keep reading like key logger which I do not want.
Also another problem is when I pressed, it read and printed then I release key then it ready again. like double printed.
(Feb-20-2023, 12:37 AM)ATARI_LIVE Wrote: [ -> ] (Feb-19-2023, 02:04 PM)Larz60+ Wrote: [ -> ]Please show your code so far (please use bbcode tags)
Difficult to advise otherwise.
import keyboard
loopstop=1
while loopstop:
keypress = keyboard.read_key()
if keypress != 0:
print(keypress)
if keypress == "esc":
loopstop=0
This code what i have problem is it will read the key anywhere in OS like I use CMD and it keep reading like key logger which I do not want.
Also another problem is when I pressed, it read and printed then I release key then it ready again. like double printed.
I got it resloved!
import msvcrt
while True:
if msvcrt.kbhit():
key = msvcrt.getch()
print(key.decode(), end='', flush=True)