Created
January 14, 2015 06:02
-
-
Save Arnoldnuo/955e1385ebdab1ce7c4c to your computer and use it in GitHub Desktop.
python在Mac上模拟键盘输入
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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