Community
Maya Programming
Welcome to Autodesk’s Maya Forums. Share your knowledge, ask questions, and explore popular Maya SDK topics.
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Contexts and keyboard key

4 REPLIES 4
Reply
Message 1 of 5
egoldid1
945 Views, 4 Replies

Contexts and keyboard key

hi, i have written one Contexts....

in this my Context i have MEvent::kMiddleMouse or MEvent::kLeftMouse...

now, how i can have MEvent::yKey( y key of keyboard):smileylol:

or how can i know what key is pressed by user?

4 REPLIES 4
Message 2 of 5
Anonymous
in reply to: egoldid1

Create a hotkeySet with commands bound to the keys which are of interest to your context.

In your context's toolOnSetup() make your hotkeySet the current one.

In your context's toolOffCleanup() restore the old hotkeySet.

 

Alternatively you can use qApp->installEventFilter(...) to install a Qt event filter which looks at the keystrokes as they come in, but you need to be careful that you don't deadlock Qt's event loop or starve Maya of events. Unless you have some compelling reason not to, I'd recommend using the hotkeySet approach.

Message 3 of 5
stuzzz
in reply to: Anonymous

Hello Joe,

 

How do you create that hotkeySet with API? Can you give some more details?

Is that with the MGlobal::executecommand()

 

Cheers.

Message 4 of 5
Anonymous
in reply to: stuzzz

We do it in MEL proc which is called by the context's toolOnSetup() and toolOffCleanup() methods using MGlobal:executeCommand() . The script containing the MEL proc is sourced by our plugin's MEL initialization script.

 

The essence of the MEL proc is:

 

global proc setHotkeys(int $enable)
{
    global string    $gOrigHotkeySet = "";

    string $curHotkeySet = `hotkeySet -q -current`;

    if ($enable)
    {
        if ($curHotkeySet == "My_Hotkeys")
        {
            warning("My Product: Nested hotkey settings detected. Please contact support.");
            return;
        }

        $gOrigHotkeySet = $curHotkeySet;

        if (!`hotkeySet -q -exists My_Hotkeys`)
        {
            hotkeySet -current My_Hotkeys;

            nameCommand -ann "Key pressed" -c "myCmd on" myBeginCmd;
            nameCommand -ann "Key released" -c "myCmd off" myEndCmd;

            hotkey -k b -n myBeginCmd -rn myEndCmd;
        }
        else
        {
            hotkeySet -e -current My_Hotkeys;
        }
    }
    else
    {
        if ($gOrigHotkeySet == "My_Hotkeys")
        {
            hotkeySet -e -current "Maya_Default";
        }
        else if ($curHotkeySet == "My_Hotkeys")
        {
            if ($gOrigHotkeySet == "")
            {
                hotkeySet -e -current "Maya_Default";
            }
            else
            {
                hotkeySet -e -current $gOrigHotkeySet;
            }
        }

        $gOrigHotkeySet = "";
    }
}

 

Message 5 of 5
stuzzz
in reply to: Anonymous

Thanks a lot!

I've seen that QuadDraw use the TAB shortcut. I feel like they use Qt framework for that. 

They might another solution beside the QApp::installEventFilter, the QAction::setShortcut seems to be a good alternative also.

 

Can't find what you're looking for? Ask the community or share your knowledge.

Post to forums  

Autodesk Design & Make Report