我需要一个在后台(或理想情况下,在Maya中)运行的Python脚本,它执行以下操作:
脚本正在运行
我按下Ctrl S,脚本检测到它
脚本模拟返回击键
脚本正在运行
What I'm still missing: 在脚本检测到CTRL S击键后立即模拟返回击键(即步骤3) .
我的代码:
import Tkinter as tk
import win32com.client as comclt
class App(object):
def __init__(self):
self.comboKeys = False
self.enterKey = False
def keyPressed(self,event):
print "--"
# if Esc is pressed, stop script
if event.keysym == 'Escape':
root.destroy()
# if CTRL+S is pressed
elif event.keysym == 's':
self.comboKeys = True
def keyReleased(self,event):
if event.keysym == 's':
self.comboKeys = False
def task(self):
if self.comboKeys:
print 'CTRL+S key pressed!'
root.after(20,self.task)
application = App()
root = tk.Tk()
print( "Press arrow key (Escape key to exit):" )
root.bind_all('', application.keyPressed)
root.bind_all('', application.keyReleased)
root.after(20,application.task)
root.mainloop()
非常感谢你!如果我遗漏了任何信息,请告诉我 .