linux系统下没有WSH可用,需要自己实现按键sendkey?python已有实现,virtkey拿来用即可。
不过需要注意的是,按键长度与延时是并行关系。
简单实现:
#!/usr/bin/python
import virtkey
import time
import threading
import sys
speed=0.25
def play(s):
tid=0
threading.Thread(target=playb,args=(tid,s)).start()
def playb(tid,s):
v=virtkey.virtkey()
ssc=list(s)
print(ssc)
for c in ssc:
v.press_unicode(ord(c))
time.sleep(speed)
for c in ssc:
v.release_unicode(ord(c))
def music(m):
m=m.strip()
codes=list(m)
oncekeys=""
state=""
for code in codes:
if code=="(":
state="once"
oncekeys=""
continue
if code==")":
state=""
play(oncekeys)
time.sleep(speed)
continue
if code=="-":
time.sleep(speed)
continue
if code=="" or code==" " or code