4

win32api.keybd_event 如何实现长按?

 2 years ago
source link: https://www.v2ex.com/t/811905
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.

V2EX  ›  程序员

win32api.keybd_event 如何实现长按?

  qq275327347 · 6 小时 40 分钟前 · 247 次点击

如题,语言是 Python ,想实现多键长按效果,目前用以下代码虽然可以实现组合键,比如 Ctrl+S ,也可以在游戏中生效,但是不能“长按”

def press_comb_key(k1,k2):

win32api.keybd_event(k1, win32api.MapVirtualKey(k1, 0), 0, 0)

win32api.keybd_event(k2, win32api.MapVirtualKey(k2, 0), 0, 0)

time.sleep(5)

win32api.keybd_event(k2, win32api.MapVirtualKey(k2, 0), win32con.KEYEVENTF_KEYUP, 0)

win32api.keybd_event(k1, win32api.MapVirtualKey(k1, 0), win32con.KEYEVENTF_KEYUP, 0)

k1 和 k2 是虚拟键码,比如“A”是“65”

谷歌了好久,也没找到解决方案,有大佬给看一下吗?


About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK