XM Magdalena 3D print, GGeorgy (3D)
LC #42 Pipers Alley

View Full Version : Challenge for a seasoned MEL coder.

04-12-2006, 02:53 PM
Is there anyone here that could help me how to script so that I could assign 2 functions in just one key?
I d'like to assign in a key the same behaviour of the space bar tap = action 1, and space bar press and hold = hotbox.

I d'like to assign tap = tool 1, and press and hold = marking menu.

Any help, please?

04-12-2006, 03:39 PM
The only marking menu that will appear on keypress is the hotbox. Regular marking menu's require a button to be pressed, (as far as I am aware).
If this is still what you'd like, I could advise, since I wrote a basic stickyKey script to mimic the key press/key hold functionality of XSI. Not really tried it on marking menu's though.

04-13-2006, 03:46 AM
i remember someone trying to simulate the same thing before here, they tried time values instead. so if you held the key for so long it would bring up the menu or if it was less than that it would execute.

try search for something along those lines.

04-13-2006, 12:23 PM
If I understood this right it shouldnt be that hard to implement.
Have a function called when the key is pressed and one when its released.
In the pressed function set a global variable. Lets say $keyDown to 1 and start a scriptJob that executes on idle an checks wether the time has run out.
If the time as run out then the scriptJob calls a function that deletes itself and executes the final command. If the pressed event occurs before that it deletets the scriptJob as well and executes the other command...

04-13-2006, 12:46 PM
global proc timedKeyDown( int $code )
global int $timedKeyStatus;
global int $timedKeyJobId;
global float $timedKeyStartTime;

$timedKeyStartTime = `timerX`;

$timedKeyStatus = $code;
$timedKeyJobId = `scriptJob -event "idle" "timedKeyTimeout()"`;

global proc timedKeyTimeout()
global int $timedKeyStatus;
global int $timedKeyJobId;
global float $timedKeyStartTime;

if( `timerX -startTime $timedKeyStartTime` > 0.2 )
evalDeferred("scriptJob -kill $timedKeyJobId;");
$timedKeyStatus = -1;
print "Timeout! Executing primary behaviour!\n";

global proc timeKeyRelease()
global int $timedKeyStatus;
global int $timedKeyJobId;

if( $timedKeyStatus != -1 )
global int $timedKeyJobId;
scriptJob -kill $timedKeyJobId;

print "Release! Executing seconday behaviour!\n";

Bind the timedKeyDown(INDEX) to the pressed event of a key and the timeKeyRelease to the release of the same key. If you wish to have this behaviour for multiple buttons just change the index on the pressed function for each hotkey. For each index do a switch in both release and timeout ($timedKeyStatus then holds the index) and execute your commands depending on that...
If you wish to change the time it takes until its timed out change the 0.2 to some other value. Right now its 200ms.
Hope that helped.

04-13-2006, 02:45 PM
I already replied to him by PM, and I think it's easier then having a scriptJob checking something on idle for his situation. If you want to have one hotkey which can be used for a marking menu or a command then you can just set an option var to true on key press and then set it to false when the marking menu gets posted. Then in the release you check to see if the optionVar is still true (i.e. the marking menu didn't get posted) and execute your command.

Of course this will work for command/MM but not command/command based on a time delay.

04-13-2006, 03:48 PM
True, but then again I think the solution posted above handles better because when keeping the key pressed you dont have to release it before the action is executed.
While you'll have to get a feeling for the time it takes until you can release the button when using the marking menu solution, in the scriptJob based one the command is executed without the user having to release the mouse first.

But then again I think it comes down to personal preference.

04-13-2006, 11:33 PM

Off the top of my head, here is what I would do...

Create a custom marking menu.

When you go to the Hotkey Editor you will see the Press and Release commands for your hotkey.

The press will look something like this:
if (`popupMenu -exists tempMM`) { deleteUI tempMM; } popupMenu -button 1 -ctl true -alt false -sh false -allowOptionBoxes true -parent viewPanes -mm 1 tempMM; source "menu_Print";

...and the Release will look something like this:
if (`popupMenu -exists tempMM`) { deleteUI tempMM; }

What you could do is add an optionVar to tell you if you've done the marking menu or not, and then if you don't use the marking menu you can execute a command in the Release.

So you could change the Press code to look somthing like this:
if (`popupMenu -exists tempMM`) { deleteUI tempMM; } optionVar -iv "myExecuteCmd" 0; popupMenu -pmc "optionVar -iv myExecuteCmd 1" -button 1 -ctl true -alt false -sh false -allowOptionBoxes true -parent viewPanes -mm 1 tempMM; source "menu_Print";

So you add an optionVar and use the -pmc flag in the popupMenu command to set it to 1. The -pmc command gets run when the popupMenu gets shown. So if you use the menu it will get set to 1 but if you don't fire up the popupMenu it will still be 0.

So then in the Release funtion you could do this:
if (`popupMenu -exists tempMM`) { deleteUI tempMM; } if (0 == `optionVar -q myExecuteCmd`) { print ("Executed command\n"); }

So when you let go of the hotkey without using the marking menu the optionVar will still be 0 and it will execute the print statement. If you did use the marking menu then the optionVar will be 1 and it won't execute the print statement.

There may be a better way of doing it but this should work.
Software Developer
Maya Modeling Team"

With the permission of goleafsgo, I posted his solution for this.

Thank you tciny, I'll try it too.

CGTalk Moderation
04-13-2006, 11:33 PM
This thread has been automatically closed as it remained inactive for 12 months. If you wish to continue the discussion, please create a new thread in the appropriate forum.