필터 지우기
필터 지우기

ginput doesn't accept keyboard entry as first input

조회 수: 1 (최근 30일)
gdell0
gdell0 2015년 8월 12일
댓글: Denis LE BRET 2016년 7월 11일
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

채택된 답변

Walter Roberson
Walter Roberson 2015년 8월 12일
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
gdell0
gdell0 2015년 8월 12일
You were right and your solution works perfectly.
Thanks!

댓글을 달려면 로그인하십시오.

추가 답변 (1개)

Denis LE BRET
Denis LE BRET 2016년 7월 7일
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
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
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?

댓글을 달려면 로그인하십시오.

카테고리

Help CenterFile Exchange에서 Annotations에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by