Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Clear current character from figure handle

543 views
Skip to first unread message

Priyanshu Agarwal

unread,
May 6, 2010, 6:09:06 PM5/6/10
to
Hi,

I'm using the following command to acquire a character from the keyboard while the focus is on a particular figure.

get(gcf,''CurrentCharacter'')

However, once the character is read the buffer is not cleared and the same character is read even the next time if I use this command in a loop. Is there a way to clear the character from the keyboard buffer?

Thanks.

Regards,
Priyanshu

Walter Roberson

unread,
May 6, 2010, 6:52:59 PM5/6/10
to

I don't think so. Well, not officially. As far as the interface is
concerned, the current character remains current until it is changed.
You are intended to use the keypress callback to detect key presses. If
you wanted to, you could have the callback stuff the character away
somewhere, and then when your loop is ready for it, it could see what
the variable currently stored and set the variable to '' afterwards.

Matt Fig

unread,
May 6, 2010, 7:59:06 PM5/6/10
to
Are you saying that the same character is read even though you are activating the keyboard while the figure is in focus? In other words, why would you expect that the current character would be changed from one reading to the next unless you type while the figure is in focus?

You can set the current character after reading it, though I am still not clear on why you would need to do this.

set(gcf,'currentch',char(1))

Priyanshu Agarwal

unread,
May 6, 2010, 9:10:07 PM5/6/10
to
What I mean is that the current character should be the character currently pressed on the keyboard. I'm trying to control a robot connected to MATLAB through serial port. So, once I read an arrow key and move the robot based on the key pressed, the key is not flushed from the buffer. This causes the robot to go crazy with the latest command and repeat it until the next key is pressed. However, current character should be empty as soon as the key is read and no other key is pressed.


"Matt Fig" <spam...@yahoo.com> wrote in message <hrvl4a$865$1...@fred.mathworks.com>...

Matt Fig

unread,
May 6, 2010, 9:35:06 PM5/6/10
to
So set it after it is read, like I showed above. Use an IF statement, or a SWITCH, so that only the allowed keys make the robot move.


%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
switch double(get(gcf,'currentch'))
case 28 % left arrow
% move left
case 29 % right arrow
% move right
case 30 % up arrow
% move up
case 31 % down arrow
% move down
otherwise
end

set(gcf,'currentch','3') % or whatever, as long as it will go to OTHERWISE.
drawnow % Flush the event queue.
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

Priyanshu Agarwal

unread,
May 6, 2010, 11:34:03 PM5/6/10
to

Setting of current character for a figure is not allowed. It results in the following error.

??? Error using ==> set
Bad property value found.
Object Name : figure
Property Name : 'CurrentCharacter'.

"Matt Fig" <spam...@yahoo.com> wrote in message <hrvqoa$4rp$1...@fred.mathworks.com>...

Walter Roberson

unread,
May 6, 2010, 11:45:10 PM5/6/10
to
Priyanshu Agarwal wrote:
>
> Setting of current character for a figure is not allowed. It results in
> the following error.
>
> ??? Error using ==> set
> Bad property value found.
> Object Name : figure
> Property Name : 'CurrentCharacter'.

It said bad property value, not that it was unwritable. What were you
trying to set it to?

Priyanshu Agarwal

unread,
May 7, 2010, 12:00:07 AM5/7/10
to
Thanks Walter. It's working now.

Walter Roberson <robe...@hushmail.com> wrote in message <a1MEn.93$7d5...@newsfe17.iad>...

Priyanshu Agarwal

unread,
May 7, 2010, 12:10:19 AM5/7/10
to
Thanks Walter. It's working now.

Walter Roberson <robe...@hushmail.com> wrote in message <a1MEn.93$7d5...@newsfe17.iad>...

0 new messages