1

I have resently started using app designer in matlab to make small programs but I'm running into a problem.

I have a app with a start button on when the user presses the start button I want to disable button and then count keypresses for a set time. After that i want to enable the button again. But when I disable the button the keypresses are no longer detected.

My current code (simplified)

function StartButtonPushed(app, event)
  app.StartButton.Enable = false;
  app.awatingResponse = true;                
  pause(20);
  app.StartButton.Enable = true;
end

function UIFigureWindowKeyPress(app, event)
  if strcmp(event.Key, 'control') % only counting the control key now
     disp('ctrl pressed') % just for testing
  end
end

if I remove app.StartButton.Enable = false; everything works but if it is there nothing happens when pressing ctrl

Lillefrog
  • 23
  • 1
  • 5

1 Answers1

0

I found a workaround using JAVA.

Add the following code after app.StartButton.Enable = false;:

robot = java.awt.Robot();
robot.mousePress(java.awt.event.InputEvent.BUTTON1_MASK);
robot.mouseRelease(java.awt.event.InputEvent.BUTTON1_MASK);

The code simulates a left mouse click.

Apparently many developers complains about the missing functionality of setting the focus to uifigure.
I found the following post that suggests using java.awt.Robot().

I can't say the solution is elegant, but it looks like it solves the problem.

Rotem
  • 30,366
  • 4
  • 32
  • 65