Override default behavior of Shift+F10

2 views (last 30 days)
E. L. Rayle
E. L. Rayle on 26 Apr 2012
Edited: Jan on 10 Oct 2017
I have a keyPress callback function associated using Guide to an application I wrote. The function is used to successfully capture and perform application specific actions for a number of keys. One key combination I try to capture is Shift+F10. I do a similar capture for all function keys including Shift+F1 thru Shift+F12. I am able to capture all the shifted function keys except Shift+F10. The callback function is never entered when Shift+F10 is pressed.
I noticed in the editing window that Shift+F10 has the effect of displaying the context menu (same as Rt-Clicking the mouse). I'm guessing MatLab is trying to display a context window in my application but since one doesn't exist, nothing happens.
QUESTION: Is there a way to override the default behavior when Shift+F10 is pressed so that my keyPress callback is called when Shift+F10 is pressed?

Answers (2)

E. L. Rayle
E. L. Rayle on 8 May 2012
I do not have a fix, but here is what I found out.
My System
MatLab R2010a - I am not able to test whether this continues to be a problem in R2012a.
Keyboard Shortcut Restrictions
The following page lists restricted keystroke combinations:
One of the restrictions is Ctrl+Shift+F10 which brings up the context menu (same as Rt-Click with mouse) for the current focus. It appears that Shift+F10 is also bringing up the context menu.
I was not able to find any documentation describing an expected behavior for Shift+F10.
Customizing Keyboard Shortcuts
The following page describes how to set user defined keyboard shortcuts via preferences.
I searched through this list for Shift+F10 and did not find it.
Summary
The problem appears to be due to Keyboard Shortcut Restrictions. Even though Shift+F10 is not listed as a restriction, it appears to have the same behavior as Ctrl+Shift+F10. It is possible that this is a bug.

John BG
John BG on 10 Oct 2017
Edited: Jan on 10 Oct 2017
Hi Rayle
the following only captures one keystroke at a time, but as long as the figure is active, no system shortcuts are executed, including shift F10, try it.
1.
Let me show you how to use figure to capture keystrokes
clear all;close all;clc
a='0';b='0'
S.fh = figure( 'units','pixels',...
'position',[500 500 200 260],...
'menubar','none','name','move_fig',...
'numbertitle','off','resize','off',...
'keypressfcn',@f_capturekeystroke,...
'CloseRequestFcn',@f_closecq);
S.tx = uicontrol('style','text',...
'units','pixels',...
'position',[60 120 80 20],...
'fontweight','bold');
guidata(S.fh,S)
function f_capturekeystroke(H,E)
% capturing and logging keystrokes
S2 = guidata(H);
P = get(S2.fh,'position');
set(S2.tx,'string',E.Key)
assignin('base','a',E.Key) % passing 1 keystroke to workspace variable
evalin('base','b=[b a]') % accumulating to catch combinations like ctrl+S
end
function f_closecq(src,callbackdata)
selection = questdlg('Close This Figure?','Close Request Function','Yes','No','Yes');
switch selection
case 'Yes'
S.fh.WindowSyle='normal'
delete(gcf)
case 'No'
return
end
end
.
2.
Regarding the crux of the query
' .. to detect a keypress and initiate action based on what key was pressed and whether or not a given different key had been pressed first .. '
the variable b contains the log of all keystrokes, sequentially logged, so one can catch combinations like ctrl+S
One can build a 2 characters window and with a switch discern any string that should trigger desired events.
.
3.
For the mouse capture, a start point for your development could be Rodney Thomson example, one of many examples compiled in a bundle available in the File Exchange to start learning GUI development, but also directly available here
[EDITED, copy righted code removed]
.
test call
.
t = linspace(-5,5);
y = sinc(t);
f = figure;
plot(t, y, 'r');
set(f, 'WindowButtonMotionFcn', @(obj, event)cursorLocation(obj, event, 'BottomLeft', ' X: %.3f\n Y: %.3f', 'r'))
.
4.
May be you can get all shortcuts overloaded with Java, the solution may be in the following reference:
Undocumented Secrets of MATLAB - Java Programming
author: Mr Yair Altman
ed: CRC Press
.
if you find this answer useful would you please be so kind to consider marking my answer as Accepted Answer?
To any other reader, if you find this answer useful please consider clicking on the thumbs-up vote link
thanks in advance
John BG
  2 Comments
Jan
Jan on 10 Oct 2017
Edited: Jan on 10 Oct 2017
And another time: Please do not post code, which is covered by a copy right without attaching the license information. See https://www.mathworks.com/matlabcentral/answers/322209-is-it-legal-to-publish-the-source-code-of-matlab-s-toolbox-functions .
It is a bad idea to collect the data in the base workspace:
assignin('base', 'a', E.Key)
evalin('base', 'b=[b a]')
Writing to the base work space has the same drawbacks as global variables. Letting the vector grow iteratively is a bad programming practice also. It would be much easier to process the events in the KeyPressFcn directly.
Guillaume
Guillaume on 10 Oct 2017
To add to that, what is the point of answering a question that is over 5 years old and concerns a very old matlab version.
Additionally, the answer completely misses the point of the question. The OP wanted to capture SHIFT+F10. The answer does not do that since shift+F10 does not raise a key press event (in R2017a as well)

Sign in to comment.

Categories

Find more on MATLAB in Help Center and File Exchange

Community Treasure Hunt

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

Start Hunting!