MATLAB: Strange Behaviour of WindowsKeyPressedFcn and ButtonDownFcn on Mac

buttondownfcnguimacMATLABwindowkeypressfcnwindowkeyreleasefcn

This is a simple example of my problem:
f = figure;
f.ButtonDownFcn = @(src,event) fprintf('clicked\n');
f.WindowKeyPressFcn = @(src,event) fprintf('pressed %s \n',event.Key);
f.WindowKeyReleaseFcn = @(src,event) fprintf('released %s \n',event.Key);
if I hold down 'o' and click on the figure, they key press function seems to die (i.e. no longer activates) though the key release function and button down function still do. If I then hold down 'j' and double click on the figure, the key press function come back to life.
MATLAB 2015b MacOS 10.12.6 (16G29)

Best Answer

Hi Elco,
I understand that you are facing an issue with using the "WindowKeyPressFcn" on Mac machine after holding down the key and clicking on the figure. I tried both the script you posted in the question and my own script, but I was not able to reproduce the issue on my system.
There is one fact worth noticing that the "WindowKeyPressFcn" callback executes whenever a key press occurs while the figure(or any of its childern) has focus.
If the issue still persists, please try to use an alternative callback function "KeyPressFcn" which could implement the similar functionality.
Please refer to the following link for more details: