在Windows上模拟按键

时间:2017-07-06 12:02:21

标签: python

我刚开始学习Python,这是我的第一个脚本:

import os, time

class Key(object):

    def __init__(self):
        self.key = 'Hello World! '
        time.sleep(3) 
        for x in range(10):
            self.simulate()

    def simulate(self):
        cmd = "osascript -e 'tell application \"System Events\" to keystroke \"" + self.key + "\"'"
        os.system(cmd)

key = Key()
key

只需在3秒后输入Hello World! 10次。

这很好但我的方法simulate(self)仅适用于OS X.我怎样才能使它在Windows上运行?

0 个答案:

没有答案
相关问题