hwnd = win32gui.FindWindow('', '')
def gkey(hwnd, key):
MAPVK_VK_TO_CHAR = 2
MAPVK_VK_TO_VSC = 0
repeat = 0x1
keycode = win32api.VkKeyScan(key)
scancode = win32api.MapVirtualKey(keycode, MAPVK_VK_TO_VSC)
lparam = win32api.MAKELONG(repeat, scancode)
win32gui.SendMessage(hwnd, win32con.WM_KEYDOWN, keycode, lparam)
time.sleep(0.1)
win32gui.SendMessage(hwnd, win32con.WM_KEYUP, keycode, lparam)