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?
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?
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.
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.
Hello Joe,
How do you create that hotkeySet with API? Can you give some more details?
Is that with the MGlobal::executecommand()
Cheers.
Hello Joe,
How do you create that hotkeySet with API? Can you give some more details?
Is that with the MGlobal::executecommand()
Cheers.
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 = "";
}
}
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 = "";
}
}
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.
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.