MATLAB Answers

Strange Behaviour of WindowsKeyPressedFcn and ButtonDownFcn on Mac

5 views (last 30 days)
Elco Bakker
Elco Bakker on 31 Oct 2017
Edited: Elco Bakker on 14 Nov 2017
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)

Accepted Answer

Jiawen Liu
Jiawen Liu on 9 Nov 2017
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:
  1 Comment
Elco Bakker
Elco Bakker on 14 Nov 2017
Dear Jiawen,
Thank you for taking a look; I guess it's just my system and I will try a fresh install.

Sign in to comment.

More Answers (0)

Community Treasure Hunt

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

Start Hunting!