ginput doesn't accept keyboard entry as first input
Show older comments
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
More Answers (1)
Denis LE BRET
on 7 Jul 2016
0 votes
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
Walter Roberson
on 7 Jul 2016
Denis, which MATLAB release are you using? There was a change in R2016a that might have affected this, so I do not want to try to debug against a different version than you are using.
Denis LE BRET
on 8 Jul 2016
I use the R2013a version.
Walter Roberson
on 8 Jul 2016
Please describe the circumstances in more detail. How many figures exist at the time you issue the ginput() ? Is it possible that the one you wish to ginput on is not the top figure? Which operating system are you using and which operating system release?
For example I just started R2012a (I had it handy) in OS-X El Capitan and with no existing figure at all (so impossible that any figure had focus) gave the command
[clicX, clicY, clicButton] = ginput(1);
and without clicking anywhere in the figure, typed a character. The ginput worked and clickButton had exactly the data that would be expected (that is, char(clickButton) was exactly what I had typed.)
... I just installed R2013a on the system described above and the results were exactly the same.
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?
Categories
Find more on Data Exploration in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!