Skip to main content
replaced http://stackoverflow.com/ with https://stackoverflow.com/
Source Link
URL Rewriter Bot
URL Rewriter Bot

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.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.

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.

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.

Source Link
cr0z3r
  • 721
  • 4
  • 9
  • 24

Python for Maya: Detect CTRL+S and then emulate a Return keystroke

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.