ginput doesn't accept keyboard entry as first input
显示 更早的评论
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
采纳的回答
更多回答(1 个)
Denis LE BRET
2016-7-7
0 个投票
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 个评论
Walter Roberson
2016-7-7
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
2016-7-8
I use the R2013a version.
Walter Roberson
2016-7-8
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
2016-7-11
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?
类别
在 帮助中心 和 File Exchange 中查找有关 Data Exploration 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!