MATLAB: Ginput doesn’t accept keyboard entry as first input

ginputkeyboard

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

Best Answer

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')