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)
import msvcrt
import pyautogui
from pynput import keyboard
kb = keyboard.Controller()
while True:
if msvcrt.kbhit():
key_stroke = msvcrt.getch()
if key_stroke == b'>':
kb.release(keyboard.Key.shift)
pyautogui.press('super')
print(key_stroke)
Solution - 2 (This will give you more control over your keyboard events)
To exit from the shell press the "Esc" key.
from pynput import keyboard
kb = keyboard.Controller()
def on_press(key):
try:
print('alphanumeric key {0} pressed'.format(
key.char))
except AttributeError:
print('special key {0} pressed'.format(
key))
def on_release(key):
print('{0} released'.format(
key))
if hasattr(key, 'char') and key.char == ">":
kb.release(keyboard.Key.shift)
kb.press(keyboard.Key.cmd)
kb.release(keyboard.Key.cmd)
if key == keyboard.Key.esc:
# Stop listener
return False
# Collect events until released
with keyboard.Listener(
on_press=on_press,
on_release=on_release) as listener:
listener.join()
# ...or, in a non-blocking fashion:
listener = keyboard.Listener(
on_press=on_press,
on_release=on_release)
listener.start()