0

i want a bot who prints the keys witch are pressed in google chrome youtube (in the search-bar). But the Code works only with keys like space, enter etc and not with 'a', 'b' etc. Here the code:

import win32gui
from pynput import keyboard

def on_press(key):
 try: key_pressed = key.char # single-char keys
 except: key_pressed = key.name # other keys
 print(key_pressed)
 active_window = win32gui.GetWindowText(win32gui.GetForegroundWindow())
 print(active_window)
 

Any Help would be apreceated (my english is not very good). Beacause every time i go on google chrome it dont recognise the keys. Please help-

Infacto
  • 5
  • 3

1 Answers1

0

Have you checked this post. It has a lot of good content on listening to keys using Python:

Detect key press in python?

EDIT:

If you want it in the background while on some other app check this:

Detecting a keypress in python while in the background

Sarthak Jain

SarthakJain
  • 1,226
  • 6
  • 11