How to know whether contextmenu item was selected by mouse or shortcut?

2 次查看(过去 30 天)
I have a uitable that I add/delete rows from using context menu selections. I have the ability to use the mouse and select the contextmenu or just CTRL+ "N" or "Z" to add/delete rows. Is there a way to know whether the callback for that menu selection is triggered by my mouse vs. the shortcut?
The problem I run into with the code below is if a user selects a cell in row 1, but then uses the mouse+contextmenu on a cell in row 2, the table.selection property is not empty so the code below thinks my user selected row 1.
if ~isempty(app.SequenceTable.Selection)
temp = app.SequenceTable.Selection;
row = temp(1);
else
row = event.InteractionInformation.Row;
end
I previously flipped it so my if statement had the condition below, but that caused a similar problem the other way.
isprop(event,'InteractionInformation')
  1 个评论
Alex
Alex 2024-3-8
One potential improvement that may work is looking at the current modifiers for the main figure:
if ~isempty(get(app.Main_UIFigure,'CurrentModifier'))
temp = app.SequenceTable.Selection;
row = temp(1);
else
row = event.InteractionInformation.Row;
end
This works for normal user input, but if someone decides to hold the CTRL button while they right-click and select an item from the context menu, then it will return the row as the currently selected cell rather than the one that was right-clicked on.

请先登录,再进行评论。

采纳的回答

Alex
Alex 2024-3-8
Looked around some more and I think my best proposal for this problem is to use the SelectionType of the app's main figure:
if strcmp(app.Main_UIFigure.SelectionType,'normal')
temp = app.SequenceTable.Selection;
row = temp(1);
else
row = event.InteractionInformation.Row;
end

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Whos 的更多信息

产品


版本

R2023b

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by