ginput doesn't accept keyboard entry as first input

10 views (last 30 days)
gdell0
gdell0 on 12 Aug 2015
Commented: Denis LE BRET on 11 Jul 2016
Hello all,
I have a figure in which I use ginput() to have coordinates. I ask the user to use left click, right click or keyboard's space in order to have coordinates of three specifics points. But ginput doesn't respond to any keyboard input till I click on the axes. After the first click it will accept all keyboard inputs.
My code:
[clicX, clicY, clicButton] = ginput(1);
while isempty(clicButton) ~= 1 % ENTER to quit
switch clicButton
case 1 % Left click
...
case 2 % Right click
...
case 32 % SPACE key
...
end
[clicX, clicY, clicButton] = ginput(1);
end
I try to add figure(handle) before ginput() in order to Matlab to focus, but whithout any results.
Is someone have a solution ?
Thanks

Accepted Answer

Walter Roberson
Walter Roberson on 12 Aug 2015
dbtype ginput
At around line 87 does it have a comment that begins with g467403 ? If so then I suspect that section to be the difficulty, that possibly before the click the wrong figure is the first child.
Possibly what might work is
uistack(handle, 'top')
  1 Comment
gdell0
gdell0 on 12 Aug 2015
You were right and your solution works perfectly.
Thanks!

Sign in to comment.

More Answers (1)

Denis LE BRET
Denis LE BRET on 7 Jul 2016
Hello,
I have the same problem, the first ginput can't be interrupted with keyboard. Your solution don't work for me, maybe I use it the wrong way. Is "handle" the handle of the figure or the handle of the axes ? I used both of them with no result. My code is attached to this answer if you please can have a look. Thank you.
  4 Comments
Denis LE BRET
Denis LE BRET on 11 Jul 2016
Hello Walter,
I confirm your example works perfectly on my configuration. the function code is attached with my first message (the uistack call is commented but I tried uncommented and the result was the same). The main difference is that the ginput function is called by a button. You are certainly right, there is a focus problem but I don't manage to solve it. Maybe because I don't use the right handle?

Sign in to comment.

Community Treasure Hunt

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

Start Hunting!

Translated by