I have got a keyboard with a non-working windows key. I tried to fix it with Python if I press the > key, the program will press the windows key, but it's not working. Here's the code:
import msvcrt
import pyautogui
while True:
if msvcrt.kbhit():
key_stroke = msvcrt.getch()
if key_stroke == b'>':
pyautogui.press('super')
print(key_stroke)
Can anyone help me? Thanks
To press ">" you need to press two keys "shift" + ".", when you release the "." key you registered ">" being a keystroke. but till that time you have not released the "shift" key.
In a nutshell when you execute pyautogui.press('super') in line 7, you are already pressing the "shift" key and then sending the "super" key command.
Solution to your problem is simple, release the "shift" key before sending the pyautogui.press('super') cmd.
The below code will resolve your problem.
Please install pynput package first (pip install pynput). Documentation for pynput
Solution - 1 (Modifying your code)
Solution - 2 (This will give you more control over your keyboard events) To exit from the shell press the "Esc" key.