0

With this simple code I want to capture keyboard events for some keys and do specific actions without printing a symbol.

import keyboard

special_keys = [ 'a', 'b', 'c' ]

def on_press(event):
    if not event.name.lower() in special_keys:
        # Work normal.
        keyboard.press(event.name)
        return False
    # Do other actions instead of printing the symbol.
    print('Special key pressed.')

keyboard.on_press(callback=on_press, suppress=True)
keyboard.wait(hotkey='esc', suppress=True)

Why some keys don't work normally, for example shift and control key and how to fix it? Windows 10, Python 3.7, keyboard 0.13.5

  • 2
    What do you mean with shift and control key don't work normally? They are not catched if you add in list? – Carlo Zanocco Sep 25 '20 at 16:50
  • I can't write some capital letters: Q, P, M with shift pressed. Also selecting a text in notepad with combination of shift and arrow keys is impossible. It looks like the problem occurs only with combination of two or more keys, e.g. Shift + something or Ctrl + something. – Paweł Grygorczuk Sep 25 '20 at 17:26

0 Answers0