Let me show you how to use figure to capture keystrokes
clear all;close all;clc
S.fh = figure( 'units','pixels',...
'position',[500 500 200 260],...
S.tx = uicontrol('style','text',...
'position',[60 120 80 20],...
S2 = guidata(H);
P = get(S2.fh,'position');
selection = questdlg('Close This Figure?','Close Request Function','Yes','No','Yes');
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.
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]
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'))
Generating a figure is the shortest way to catch keystrokes (and mouse), but if you want to spend time Java, then one can 'lift the bonnet' of the operative system used and catch keystrokes there. I don't know how it works, but I know it's explained here:
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