Home Technical Talk

Maya 2009: A Better Hotkey Editor?

polycounter lvl 18
Offline / Send Message
killingpeople polycounter lvl 18
Hi guys,
I have a script/plugin request. Can you help?

It would work similar to creating a new shelf shortcut on the fly (holding Shift+Ctrl, left-click on a menu item)
I’d love for the ability to call upon a small prompt that would list my previous action, allow me to assign a key or key combination (Shift, Ctrl, Alt, Check-boxes) of my choosing. It would warn me of hotkey conflicts and would save the change after clicking an "OK" or "Apply" box.

TL;DR: I’d love for the ability to assign hotkeys on the fly in Maya.

Thanks for your consideration!

-kp

Replies

  • pior
    Options
    Online / Send Message
    pior grand marshal polycounter
    Once you create a icon in a shelf with shift+ctrl click, you can then middle-click drag it to the mel command line and/or the keyboard shortcut editor (in the User category) after creating a new empty shortcut in there. From there you can assign any key binding you want. And then, delete the temp shelf icon my middle-click dragging to the recycle bin on the far right.

    (my point being : By creating a shortcut this way, you have full control on it, without having to hunt down a function in the existing list in the keyboard shortcut editor)

    Obviously that doesn't work as a dedicated script but I thought I'd mention this tip anyways.
  • killingpeople
    Options
    Offline / Send Message
    killingpeople polycounter lvl 18
    That is a handy approach! Thanks for the reply pior ;)
  • PolyHertz
    Options
    Offline / Send Message
    PolyHertz polycount lvl 666
    Here ya go.

    It'll take the last command that Maya placed in the Recent Command List and let you assign a hotkey to it (via pressing enter/return in the textfield). The top menu bar text will let you know what that command is called before you assign a key, and a warning will pop up if you try to overwrite an existing hotkey.

    It wont work if you throw a script at it atm (ie it cant assign a hotkey to itself), but should be fine for most native maya commands.
    //RepeatLast Hotkeyer v1
    
    if (`window -exists rlHotkey`)
        deleteUI rlHotkey;
    window -wh 220 75 -mxb 0 -title "RepeatLast Hotkeyer" rlHotkey;
    
    frameLayout -bs "etchedOut" -w 200 -cll 0 -l "Enter Hotkey";
    formLayout selForm;
        textField -aie 1 -enterCommand newHKProc txtFld1;
        checkBox -label "Alt" boxyAlt;
        checkBox -label "Ctrl" boxyCtrl;
    
        formLayout -edit
        -af txtFld1 left 0
        -ap txtFld1 right 0 50
        
        -ap boxyAlt right 2 75
        
        -af boxyCtrl right 0
        -ap boxyCtrl left 2 75
        selForm;
    
    showWindow rlHotkey;
    $sj_rcc = `scriptJob -p rlHotkey -e RecentCommandChanged rlMonitor`;
    
    
    
    
    //---------------------------Procedures-----------------------------------
    
    
    global proc rlMonitor () //Keeps the menu bar updated with the last command
    {
    $lastCmd = `repeatLast -q -i`;
    window -edit -title $lastCmd rlHotkey;
    }
    
    
    
    global proc warnWinProc () //Warns the user they are about to overwrite a hotkey
    {
    global string $usedCmd;
    
    if (`window -exists hkWarning`)
        deleteUI hkWarning;
    window -wh 220 75 -mxb 0 -title "WARNING" hkWarning;
    
    columnLayout;
    text -align "left" -l "This key is already assigned to:";
    text -align "center" -l $usedCmd;
    rowLayout -nc 2 -ct2 "left" "right";
    button -c "finalHotkeyProc" -label "Replace";
    button -c "deleteUI hkWarning" -label "Cancel";
    
    showWindow hkWarning;
    }
    
    
    
    global proc newHKProc () //What's called when Enter is pressed after entering new hotkey
    {
    global string $usedCmd;
    $curText = `textField -q -text txtFld1`; //letter status
    
    //Make sure the specified hotkey isnt already taken
    if (size($usedCmd = `hotkeyCheck -k $curText`) > 0 ||
        size($usedCmd = `hotkeyCheck -k $curText -alt`) > 0 ||
        size($usedCmd = `hotkeyCheck -k $curText -ctl`) > 0 ||
        size($usedCmd = `hotkeyCheck -k $curText -alt -ctl`) > 0) warnWinProc;
    else
        {finalHotkeyProc;}
    }
    
    
    
    
    global proc finalHotkeyProc ()
    {
    $modifs[0] = `checkBox -q -v boxyAlt`; //alt status
    $modifs[1] = `checkBox -q -v boxyCtrl`; //ctrl status
    $curText = `textField -q -text txtFld1`; //letter status
    $lastCmd = `repeatLast -q -i`; //The command we need to assign hotkey to
    nameCommand -annotation $lastCmd -command $lastCmd $lastCmd; //needed before can use hotkey command
    
    if (($modifs[0] == 0) && ($modifs[1] == 0)) hotkey -k $curText -name $lastCmd;
    if (($modifs[0] == 1) && ($modifs[1] == 0)) hotkey -k $curText -alt -name $lastCmd;
    if (($modifs[0] == 0) && ($modifs[1] == 1)) hotkey -k $curText -ctl -name $lastCmd;
    if (($modifs[0] == 1) && ($modifs[1] == 1)) hotkey -k $curText -alt -ctl -name $lastCmd;
    
    print "Hotkey assigned.";
    
    if (`window -exists hkWarning`)
        deleteUI hkWarning;
    }
    
    
    
    
    rlMonitor; //Makes sure the rlMonitor runs at tools startup
    
  • killingpeople
    Options
    Offline / Send Message
    killingpeople polycounter lvl 18
    Dude! I can't wait to try this shit out! *rides bike to work furiously*
  • Autocon
    Options
    Offline / Send Message
    Autocon polycounter lvl 15
    Greg you just know how to make this silly program actually usable with your scripting powers. :)
  • PolyHertz
    Options
    Offline / Send Message
    PolyHertz polycount lvl 666
    Necro bump. Just went back and updated this script so it'd work correctly with newer versions of maya:
    //RepeatLast Hotkeyer v2
    
    if (`window -exists rlHotkey`)
        deleteUI rlHotkey;
    window -wh 250 50 -mxb 0 -title "RepeatLast Hotkeyer" rlHotkey;
    
    frameLayout -bs "etchedOut" -w 200 -cll 0 -l "Enter Hotkey";
    formLayout selForm;
        textField -aie 1 -enterCommand newHKProc txtFld1;
        checkBox -label "Alt" boxyAlt;
        checkBox -label "Ctrl" boxyCtrl;
    
        formLayout -edit
        -af txtFld1 left 0
        -ap txtFld1 right 0 50
        
        -ap boxyAlt right 2 75
        
        -af boxyCtrl right 0
        -ap boxyCtrl left 2 75
        selForm;
    
    showWindow rlHotkey;
    $sj_rcc = `scriptJob -p rlHotkey -e RecentCommandChanged rlMonitor`;
    
    
    
    
    //---------------------------Procedures-----------------------------------
    
    
    
    global proc rlMonitor () //Keeps the menu bar updated with the last command
    {
    global string $lastCmd;
    $lastCmd = `repeatLast -q -i`;
    window -edit -title $lastCmd rlHotkey;
    }
    
    
    
    
    
    global proc newHKProc () //What's called when Enter is pressed after entering new hotkey
    {
    global string $lastCmd;
    global string $usedCmdPress;
    global string $usedCmdRelease;
    $usedCmdPress = 0;
    $usedCmdRelease = 0;
    
    $curLetter = `textField -q -text txtFld1`; //Letter the user wants to use for the hotkey
    $modifs[0] = `checkBox -q -v boxyAlt`; //alt status
    $modifs[1] = `checkBox -q -v boxyCtrl`; //ctrl status
    
    //Hotkey assigned as a press command?
    if (($modifs[0] == 0) && ($modifs[1] == 0)) $usedCmdPress = `hotkey -q -name $curLetter`;
    if (($modifs[0] == 1) && ($modifs[1] == 0)) $usedCmdPress = `hotkey -q -alt -name $curLetter`;
    if (($modifs[0] == 0) && ($modifs[1] == 1)) $usedCmdPress = `hotkey -q -ctl -name $curLetter`;
    if (($modifs[0] == 1) && ($modifs[1] == 1)) $usedCmdPress = `hotkey -q -alt -ctl -name $curLetter`;
    //Hotkey assigned as a release command?
    if (($modifs[0] == 0) && ($modifs[1] == 0)) $usedCmdRelease = `hotkey -q -releaseName $curLetter`;
    if (($modifs[0] == 1) && ($modifs[1] == 0)) $usedCmdRelease = `hotkey -q -alt -releaseName $curLetter`;
    if (($modifs[0] == 0) && ($modifs[1] == 1)) $usedCmdRelease = `hotkey -q -ctl -releaseName $curLetter`;
    if (($modifs[0] == 1) && ($modifs[1] == 1)) $usedCmdRelease = `hotkey -q -alt -ctl -releaseName $curLetter`;
    
    //Make sure the specified hotkey isnt already taken
    if ($usedCmdPress != 0 || $usedCmdRelease != 0) warnWinProc;
    else {finalHotkeyProc;}
    }
    
    
    
    
    
    global proc warnWinProc () //Warns the user they are about to overwrite a hotkey
    {
    global string $lastCmd;
    global string $usedCmdPress;
    global string $usedCmdRelease;
    
    if (`window -exists hkWarning`)
        deleteUI hkWarning;
    window -wh 220 125 -mxb 0 -title "WARNING" hkWarning;
    
    columnLayout;
    text -align "left" -l "This key is already assigned to:";
    text -align "left" -l "Press:"; text -align "center" -l $usedCmdPress;
    text -align "left" -l "Release:"; text -align "center" -l $usedCmdRelease;
    text -align "left" -l "";
    rowLayout -nc 2 -ct2 "left" "right";
    button -c "finalHotkeyProc" -label "Replace";
    button -c "deleteUI hkWarning" -label "Cancel";
    
    showWindow hkWarning;
    }
    
    
    
    
    
    global proc finalHotkeyProc () //Assigns hotkey to new command
    {
    global string $lastCmd;
    $modifs[0] = `checkBox -q -v boxyAlt`; //alt status
    $modifs[1] = `checkBox -q -v boxyCtrl`; //ctrl status
    $curText = `textField -q -text txtFld1`; //letter status
    nameCommand -annotation $lastCmd -command $lastCmd $lastCmd; //needed before can use hotkey command
    
    //Remove hotkey from old command, just to be safe.
    hotkey -k $curText -name "";
    hotkey -k $curText -releaseName "";
    
    //Assign hotkey to new command
    if (($modifs[0] == 0) && ($modifs[1] == 0)) hotkey -k $curText -rcr 1 -releaseName $lastCmd;
    if (($modifs[0] == 1) && ($modifs[1] == 0)) hotkey -k $curText -rcr 1 -alt -releaseName $lastCmd;
    if (($modifs[0] == 0) && ($modifs[1] == 1)) hotkey -k $curText -rcr 1 -ctl -releaseName $lastCmd;
    if (($modifs[0] == 1) && ($modifs[1] == 1)) hotkey -k $curText -rcr 1 -alt -ctl -releaseName $lastCmd;
    
    savePrefs -hotkeys;
    print "Hotkey assigned.";
    
    if (`window -exists hkWarning`)
        deleteUI hkWarning;
    }
    
    
    rlMonitor; //Makes sure the rlMonitor runs at tools startup
    
    It fixes the problem where it would bypass the overwrite warning message (they broke the hotkeyCheck command at some point), and some other stuff.
Sign In or Register to comment.