在Python中模拟键盘按钮按下的最佳方法是什么

时间:2016-02-11 16:11:11

标签: python keyboard ctypes keyboard-events win32com

我尝试过ctypes:

def a():
    SendInput(Keyboard(KEY_A))
    time.sleep(0.1)
    SendInput(Keyboard(KEY_A, KEYEVENTF_KEYUP))
    time.sleep(0.05)

和win32com.client SendKeys:

import win32com.client
import time

shell = win32com.client.Dispatch("WScript.Shell")


def key_pause():
    time.sleep(0.03)


def a():
    shell.SendKeys("{a}", 0)
    key_pause()

到目前为止,许多程序仍然没有注册它们。有没有办法模拟键盘按键按下,每次在任何程序中都会成功?我在Windows 10上工作。

0 个答案:

没有答案
相关问题