Reputation: 721
I need a Python script that runs in the background (or ideally, within Maya) and that does the following:
Currently, following some answers here and there, I can successfully detect the CTRL+S keystrokes. I tried following this answer to emulate a keystroke with WScript.Shell, but was unsuccessful.
What I'm still missing: Emulating a Return keystroke (i.e. step 3), right after the script has detected a CTRL+S keystroke.
My code:
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()
Thank you very much! And please do let me know if I missed any sort of information.
Upvotes: 0
Views: 1124
Reputation: 12208
If you're commited to TK and you need to run it but not to interact with Maya directly, you can just fire off a separate process with your TK applications and talk to it via the maya command port, or by using a library like rpyc or zeromq to send events to Maya. It's a pain, because you have to serialize communications back and forth.
It might help us if you were more clear on what's going on inside the app. Is it text entry you're trying to do?
Upvotes: 0