+ 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.

5th Sep 2019, 5:51 AM
CoderBittu
CoderBittu - avatar
11 Respostas
+ 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
5th Sep 2019, 7:47 AM
CoderBittu
CoderBittu - avatar
+ 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 )
5th Sep 2019, 6:55 AM
Trigger
Trigger - avatar
+ 2
Ya thanks your code also helped me a lot to find my solution
5th Sep 2019, 7:53 AM
CoderBittu
CoderBittu - avatar
+ 1
Its giving invalid syntax bro
5th Sep 2019, 7:06 AM
CoderBittu
CoderBittu - avatar
+ 1
Whoopsie forgot that last partđŸ€Ł It works now?
5th Sep 2019, 7:48 AM
Trigger
Trigger - avatar
+ 1
Yeah😂😂😂😂
5th Sep 2019, 7:49 AM
CoderBittu
CoderBittu - avatar
+ 1
It doesn't print key code still, it's ok for my developing something important
5th Sep 2019, 7:50 AM
CoderBittu
CoderBittu - avatar
0
Did you install pynput?
5th Sep 2019, 7:33 AM
Trigger
Trigger - avatar
0
When I get access to a real pc ill check out the problem
5th Sep 2019, 7:35 AM
Trigger
Trigger - avatar
0
Also, you cant run it on sololearn
5th Sep 2019, 7:35 AM
Trigger
Trigger - avatar
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
5th Sep 2019, 7:52 AM
Trigger
Trigger - avatar