0

I need a Python script that runs in the background (or ideally, within Maya) and that does the following:

  1. Script is running
  2. I press Ctrl+S, script detects it
  3. Script emulates a Return keystroke
  4. Script is running

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.

6
  • I don't think its a good idea to use Tkinter with maya Commented Aug 7, 2013 at 11:09
  • Because it will not interface well with maya. Use QT or the builting gui framework. Remember your not building a gui for a software, your just building part of an gui inside another gui being able to interact with that other gui is important Commented Aug 7, 2013 at 12:10
  • Hmm, got it. Do you have any alternatives in mind? Problem is, I'm running on a tight deadline and I felt like this script was almost finished. Commented Aug 7, 2013 at 19:20
  • Why not use mayas own hotkey facility? Commented Aug 7, 2013 at 19:33
  • Because, as far as I know, I cannot emulate keystrokes. Commented Aug 7, 2013 at 19:39

1 Answer 1

0

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?

Sign up to request clarification or add additional context in comments.

3 Comments

Hey, thanks. Problem is: I use Maya 2014 (Student version), which pops up a "this was created with the student version" message every time I save, auto-save, and for every reference(s) I have in my scene. My current scene has a reference in it, so it pops-up that student-message box twice. This is incredibly slowing down my workflow.. so I thought: Detect CTRL+S then emulate 2 Return keystrokes. That's what I want to do. @joojaa Helped me with this: pastie.org/8218563 which I call from Maya, but I'm not sure whether that script is already doing something/being run.
Oh wow, thanks for that. But I would like to create this myself (for learning purposes also). Any way you could help me out? I would like to see whether my os.system("path_to_file") call is doing something. I can see a DOS window open-close quickly, but perhaps I could print "script running" somewhere? Thank you!
the dos window proves that your system call is getting fired, but you dont get much back from it. You might try using python's subprocess module instead, which will let you capture the output of the other tool and any return codes that come back from it. Some examples here:stackoverflow.com/questions/10406532/…

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.