Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
KEY input....
#1
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?
Reply
#2
Please show your code so far (please use bbcode tags)
Difficult to advise otherwise.
Reply
#3
deleted
Reply
#4
Delete
Reply
#5
(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.
Reply
#6
(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)
jefsummers likes this post
Reply


Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020