Skip to content

Instantly share code, notes, and snippets.

@jackyshan
Created March 24, 2016 14:58
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jackyshan/df1dd731683cdc0fc327 to your computer and use it in GitHub Desktop.
Save jackyshan/df1dd731683cdc0fc327 to your computer and use it in GitHub Desktop.
模拟键盘输入
import os
import time
import thread
from datetime import datetime
cmd = """
osascript -e 'tell application "System Events" to keystroke " "'
"""
def pressSpace(sign, sign1):
i = 0
while i < 1000:
print datetime.now()
os.system(cmd)
i = i + 1
print sign + str(i)
if __name__ == '__main__':
print 'thread test a'
time.sleep(15)
thread.start_new_thread(pressSpace, ('a', 'a'))
time.sleep(300)
# 主线程结束后,Thread生成的线程会自动退出,所以需要在主线程上加入time.sleep(300)等待子线程结束后再停止主线程。
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment