Is it possible to ignore Hotkeys in custom MPxContext?

Is it possible to ignore Hotkeys in custom MPxContext?

jmreinhart
Advisor Advisor
382 Views
3 Replies
Message 1 of 4

Is it possible to ignore Hotkeys in custom MPxContext?

jmreinhart
Advisor
Advisor

I have a custom context and I would like to be able to hit a key (at the moment I am using "x" as the test key), and then enter a mode where I can type a number and press enter and the context will use that value I typed in.

 

I have most of it working and I am able to get the numerical value but I am having two issues:

  1. The "x" key is triggering the grid snapping when I press it and ideally I would like to prevent this when in my context.
  2. The backspace and delete keys modify the selection in the scene.

Is it possible to override or disable these behaviors somehow? The best I can come up with is to restore the selection and create a temporary set of hotkeys that I switch to, but I was hoping someone could offer a more robust solution,

 

 

 

0 Likes
Accepted solutions (1)
383 Views
3 Replies
Replies (3)
Message 2 of 4

brentmc
Autodesk
Autodesk
Accepted solution

Not my area of expertise but you need to look into setting up a Custom hotkey context for your tool. Custom hotkey contexts are designed to allow tools/editors to override global hotkeys.

 

    hotkeyCtx -t "Tool" -ac "MyCustomToolName";

next you can setup a runtimeCommand with your custom context:

    runTimeCommand -hotkeyCtx  "MyCustomToolName" ... MyCustomHotkeyAction;

and finally you can bind that to a hotkey:

    hotkey -k "x" -name "MyCustomHotkeyAction";
 
You should be able to find exampled of this by poking around in the Mel files installed with Maya. e.g. hotkeySetup.mel.
Brent McPherson
Principle Engineer
0 Likes
Message 3 of 4

jmreinhart
Advisor
Advisor

Thanks brent, I will give that a try and post my results.

0 Likes
Message 4 of 4

jmreinhart
Advisor
Advisor

So this worked for temporary disabling the hotkeys when my custom context was active.

# Tool On Setup
currentSet = cmds.hotkeySet(q = True, current = True)
tempSet = cmds.hotkeySet("currentSet_temp",source = currentSet)
cmds.hotkeySet(tempSet, e = True, current = True)
cmds.hotkey(k = "x", name = "")
cmds.hotkey(k = "v", name = "")
cmds.hotkey(k = "c", name = "")

# Tool on Cleanup
currentSet = cmds.hotkeySet(currentSet, e = True, current = True)
currentSet = cmds.hotkeySet(tempSet, e = True, delete = True)

But I couldn't find a way to override the backspace and delete keys. So I think I'm going to try and see if this sort of thing will work with my context (I will post results).

jonahrnhrt_0-1664054147402.png