Record Attribute for one frame

76 views
Skip to first unread message

Isai Calderon

unread,
Feb 7, 2018, 3:09:43 PM2/7/18
to Python Programming for Autodesk Maya
Hi folks,

For today's toy, I am attempting to run a script while the mouse is manipulating an object.

```
Use-case:
While moving item, press hotkey to set key and move one frame forward. Mouse manipulation is still live on the item.
The hotkey can be repeated indefinitely.
```

I am using Pymel, and am looking into a scriptJob to do this, but not sure which `Event` or `Condition` to use, or if it should be a new `context` tool instead (or combine them)...

Any thoughts?

Thank you!

Isai

Michael Boon

unread,
Feb 7, 2018, 8:27:04 PM2/7/18
to Python Programming for Autodesk Maya
So your problem is that Maya doesn't notice the hotkey being pressed while the mouse is down?

Maya doesn't appear to have a scriptJob or an MMessage for a key being pressed.

If you're familiar with Qt, you could try using a Qt event handler. I'm sure you could detect the key being pressed, but there's no guarantee that you could get Maya to act on it.

If you're not familiar with Qt, learning how to set up a handler is a fair bit of effort for something that may not work at all. Hopefully, someone else will have a better idea.

Isai Calderon

unread,
Feb 8, 2018, 12:12:20 PM2/8/18
to Python Programming for Autodesk Maya
That's exactly what I'd like to do. I'm not too familiar with Qt yet, but I did realize that I could try running a loop through python that could recognize a keypress while the mouse is held down. I could start the python loop while the mouse is pressed down, and end the loop with a mouse-release. The problem then becomes this:

Does Python have a way to detect a keypress?

Thanks!!

Michael Boon

unread,
Feb 8, 2018, 5:18:35 PM2/8/18
to Python Programming for Autodesk Maya
Not Python itself, but Qt has a way. You probably don't want to run a loop, but use Qt's event handler system. To do this, you create an instance of a custom Qt class and "install" it as an "event handler" on the main Maya window (or on a viewport). Then in the eventFilter() method of your class, you look for QKeyEvent, check the key, and if it's the one you want, you run your code.

There are a lot of links in that chain, so try something really simple first, like printing the event you get. Just be aware that if you print for every event (rather than only for QKeyEvent) you will hang Maya because there are so many events it will clog up the Script Editor.

This post:
https://groups.google.com/d/msg/python_inside_maya/Auiy06xVqLo/61sqMp_2AQAJ
show an example of putting an event handler on the main Maya window, in this case to detect Drop events. You could adjust it to detect keystrokes. It was written for Maya 2015 (where the version of Qt was PySide) so you may need to adjust it to use PySide2 as well.
Reply all
Reply to author
Forward
0 new messages