MATLAB Answers

0

How to use windowkeypressfcn

Asked by Brenda FOCHIVÉ on 9 May 2019
Latest activity Commented on by Brenda FOCHIVÉ on 10 May 2019
I have written a 5code that draws a graph. I want that each time the user clicks on escape the graph comes back to its original state. This is my code:
Figure('windowkeypressfcn',@keyP)
Function keyP(source, event)
KeyPressed=eventData.key;
If strcmp(KeyPressed,'escape')
View (3)
end
end
When I run it shows errors. It says The class "eventdata" is undefined. Perhaps java is not running

  0 Comments

Sign in to comment.

1 Answer

Answer by Kevin Phung on 9 May 2019
Edited by Kevin Phung on 9 May 2019

function keyP(source, event)
KeyPressed=event.Key;
if strcmp(KeyPressed,'escape')
view(3)
end
end
It's as the error says. You never defined a variable eventData. Your input is 'event'

  1 Comment

I have edited it but when I click on escape key the function do not run. I instead see the command window pop up. It's like the figure do not have the focus again.

Sign in to comment.