+ 2
Python get keycode in Windows
I am trying to make python a program that whenever we press a key on keboard the keycode of the key will print up here's the C code i want to turn into python #include <stdio.h> #include <conio.h> int main(){ while(1){ if(kbhit){ int x = getch() printf("%d",x); } } } does anyone have this code solution please? code example will be more helpful Thanking you.
11 ответов
+ 3
I installed pynput bro
And got a solution too , the problem with listener
Here's solution
with Listener (
on_press = on_press
) as listener:
listener.join()
Thanks
+ 2
Install pynput (my fave keymonitor module)
# code to print out key pressed and char code until escape pressed
from pynput.keyboard import Key, Listener
def on_press(key):
if key == Key.esc:
return False
print(f"{key} pressed: {ord(key)}")
with Listener(
on_press = on_press
)
+ 2
Ya thanks your code also helped me a lot to find my solution
+ 1
Its giving invalid syntax bro
+ 1
Whoopsie forgot that last part🤣
It works now?
+ 1
Yeah😂😂😂😂
+ 1
It doesn't print key code still, it's ok for my developing something important
0
Did you install pynput?
0
When I get access to a real pc ill check out the problem
0
Also, you cant run it on sololearn
0
Hmmm. Yeah. Ill have to check later on my computer🤔 Im working off of google and a guess at what kind of values are returned