Skip to main content
Legend
December 3, 2025
Answered

When the Shift key is pressed. I want to change the right-click menu.

  • December 3, 2025
  • 1 reply
  • 277 views

When the Shift key is pressed. I want to change the right-click menu.

I'm testing behavior in the C++ SDK with IMenuFilter's FilterMenuItem.

// #include "KeyStates.h"
if (::IsShiftKeyPressed()) CAlert::InformationAlert("");


It responds to the right-click menu when a text frame is selected, but it doesn't respond to the right-click menu when nothing is selected. Is this expected?

 

Also, I'm trying to implement this in the C++ SDK, but is it possible with Script?

Correct answer 琥珀 猫太郎

By using IDynamicMenu and kSetMenuCustomizationPrefsCmdBoss, I was able to change the right-click menu layout depending on whether the Shift key is pressed or not.

// SDK Sample DynMnu.
//DynMnu.fr

// Placeholder for dynamic menu entries
kDynMnuPlaceholderActionID, // ActionID (kInvalidActionID for positional entries)
"RtMouseDefault", // Menu Path.
0, // Menu Position placeholder.
kSDKDefIsDynamicMenuFlag, // Flag for dynamic menu

kDynMnuStaticMenuActionID,
"RtMouseDefault",
0,
kSDKDefIsNotDynamicMenuFlag,

// DynMnuDynamicMenu.cpp
// DynMnuDynamicMenu::RebuildMenu
InterfacePtr<ICommand> iCommand(CmdUtils::CreateCommand(kSetMenuCustomizationPrefsCmdBoss));
InterfacePtr<IMenuCustomizationData> iMenuCustomizationData(iCommand, UseDefaultIID());
if (IsShiftKeyPressed() == kTrue) // #include "KeyStates.h
{
	if (iMenuCustomizationData->IsMenuActionHidden(kDynMnuStaticMenuActionID) == kTrue)
	{
		iMenuCustomizationData->ShowMenuAction(kDynMnuStaticMenuActionID);
	}
}
else
{
	if (iMenuCustomizationData->IsMenuActionHidden(kDynMnuStaticMenuActionID) == kFalse)
	{
		iMenuCustomizationData->HideMenuAction(kDynMnuStaticMenuActionID);
	}
}
CmdUtils::ProcessCommand(iCommand);

 

By setting kDynMnuStaticMenuActionID as the script's action ID, you can also register the script.

1 reply

Legend
December 6, 2025

IMenuFilter seems to trigger the FilterMenuItem method when menus are registered.
I explored other methods.

I tried using IEventWatcher.

// My.fr
AddIn
{
	kSessionBoss,
	kInvalidClass,
	{
		IID_IMYEVENTWATCHER, kMyEventWatcherImpl,
	}
},

// MyEventWatcher.cpp
IEventDispatcher::EventTypeList MyEventWatcher::WatchEvent(IEvent* e)
{
	if (e->GetType() == IEvent::kRButtonDn && e->ShiftKeyDown())
	{
		CAlert::InformationAlert("");
	}

	return IEventDispatcher::EventTypeList(IEvent::kRButtonDn);
}

void MyEventWatcher::StartWatching()
{
	if (fWatching == kTrue) return;
	
	InterfacePtr<IApplication> iApplication(::GetExecutionContextSession()->QueryApplication());
	InterfacePtr<IEventDispatcher> iEventDispatcher(iApplication, ::UseDefaultIID());
	if (iEventDispatcher)
	{
		IEventDispatcher::EventTypeList eventTypeList(IEvent::kRButtonDn);
		iEventDispatcher->AddEventWatcher(this, eventTypeList);
		fWatching = kTrue;
	}
}

// MyScriptProvider.cpp
InterfacePtr<IEventWatcher> iEventWatcher(::GetExecutionContextSession(), IID_IMYEVENTWATCHER);
iEventWatcher->StartWatching();

It now responds to Shift+right-click.
However, I still don't know how to hide the existing menu and display my own menu from here...

琥珀 猫太郎AuthorCorrect answer
Legend
December 7, 2025

By using IDynamicMenu and kSetMenuCustomizationPrefsCmdBoss, I was able to change the right-click menu layout depending on whether the Shift key is pressed or not.

// SDK Sample DynMnu.
//DynMnu.fr

// Placeholder for dynamic menu entries
kDynMnuPlaceholderActionID, // ActionID (kInvalidActionID for positional entries)
"RtMouseDefault", // Menu Path.
0, // Menu Position placeholder.
kSDKDefIsDynamicMenuFlag, // Flag for dynamic menu

kDynMnuStaticMenuActionID,
"RtMouseDefault",
0,
kSDKDefIsNotDynamicMenuFlag,

// DynMnuDynamicMenu.cpp
// DynMnuDynamicMenu::RebuildMenu
InterfacePtr<ICommand> iCommand(CmdUtils::CreateCommand(kSetMenuCustomizationPrefsCmdBoss));
InterfacePtr<IMenuCustomizationData> iMenuCustomizationData(iCommand, UseDefaultIID());
if (IsShiftKeyPressed() == kTrue) // #include "KeyStates.h
{
	if (iMenuCustomizationData->IsMenuActionHidden(kDynMnuStaticMenuActionID) == kTrue)
	{
		iMenuCustomizationData->ShowMenuAction(kDynMnuStaticMenuActionID);
	}
}
else
{
	if (iMenuCustomizationData->IsMenuActionHidden(kDynMnuStaticMenuActionID) == kFalse)
	{
		iMenuCustomizationData->HideMenuAction(kDynMnuStaticMenuActionID);
	}
}
CmdUtils::ProcessCommand(iCommand);

 

By setting kDynMnuStaticMenuActionID as the script's action ID, you can also register the script.

Legend
December 17, 2025

I've made it into a PlugIn.
Please give it a try if you like.

KohakuNekotarou/KohakuExtendScriptShiftRtMouseMenu: InDesign C++ SDK Plug-In