I need a Python script that runs in the background (or ideally, within Maya) and that does the following:
- Script is running
- I press Ctrl+S, script detects it
- Script emulates a Return keystroke
- 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.Shellthis 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.