Key Presses in Python

2019-01-06 14:27发布

Is it possible to make it appear to a system that a key was pressed, for example I need to make A key be pressed thousands of times, and it is much to time consuming to do it manually, I would like to write something to do it for me, and the only thing I know well enough is Python.

A better way to put it, I need to emulate a key press, I.E. not capture a key press.

More Info (as requested): I am running windows XP and need to send the keys to another application.

7条回答
不美不萌又怎样
2楼-- · 2019-01-06 14:54

Alternative way to set prefer window into foreground before send key press event.

hwnd = win32gui.FindWindowEx(0,0,0, "App title")
win32gui.SetForegroundWindow(hwnd)
查看更多
登录 后发表回答