Thread Subject: WindowKeyPressFcn not working in zoom/pan mode

Subject: WindowKeyPressFcn not working in zoom/pan mode

From: Emma

Date: 18 Feb, 2010 23:58:04

Message: 1 of 4

Hi everyone,
I am working on a GUI that registers whenever the user presses the left-arrow key or right-arrow key using WindowKeyPressFcn. If the GUI is in zoom or pan mode, however, it doesn't register the key presses anymore. I tried using the ButtonDownFilter zoom/pan callback, but this doesn't seem to work. Any suggestions would be greatly appreciated.
Thanks,
Emma

Subject: WindowKeyPressFcn not working in zoom/pan mode

From: Matthew Whitaker

Date: 19 Feb, 2010 00:45:19

Message: 2 of 4

"Emma " <etm1@fuse.net> wrote in message <hlkk6c$go9$1@fred.mathworks.com>...
> Hi everyone,
> I am working on a GUI that registers whenever the user presses the left-arrow key or right-arrow key using WindowKeyPressFcn. If the GUI is in zoom or pan mode, however, it doesn't register the key presses anymore. I tried using the ButtonDownFilter zoom/pan callback, but this doesn't seem to work. Any suggestions would be greatly appreciated.
> Thanks,
> Emma

Hi Emma,

The uimodemanager turns off most of your windows callbacks when you go into modes like pan and zoom

You should be able to do this by directly creating a listener.

If you run the function below you should still be able to listen for keystrokes even when in zoom mode.

function keyListenerDemo

%set up a figure
h = figure;
plot(sin(0:0.1:2*pi));

addlistener(h,'WindowKeyPress',@keyPress);

    function keyPress(src,evtData)
        key = get(src,'CurrentCharacter');
        switch key
            case ','
                disp('Left Arrow')
                
            case '.'
                disp('Right Arrow')
        end %switch
    end %keyPress

end %keyListenerDemo

hope this helps
Matt W

Subject: WindowKeyPressFcn not working in zoom/pan mode

From: Emma

Date: 19 Feb, 2010 03:05:19

Message: 3 of 4

Hi Matt,
Thank you so much for your answer. Addlistener seems to work really well, except for some weird characteristics that I can't figure out:
- Why does addlistener(gcf,'WindowKeyPress',@keyPress) work but not addlistener(gcf,'WindowKeyPressFcn',@keyPress)? I would think that the latter would work just as well as the former, since WindowKeyPressFcn is a figure property.
- Why does addlistener not let me pass handles? ie., addlistener(gcf,'WindowKeyPress',{@keyPress,handles}) throws an error.
Thank you so much for your help.
Emma

Subject: WindowKeyPressFcn not working in zoom/pan mode

From: Matthew Whitaker

Date: 22 Feb, 2010 17:20:21

Message: 4 of 4

"Emma " <etm1@fuse.net> wrote in message <hlkv5f$kfn$1@fred.mathworks.com>...
> Hi Matt,
> Thank you so much for your answer. Addlistener seems to work really well, except for some weird characteristics that I can't figure out:
> - Why does addlistener(gcf,'WindowKeyPress',@keyPress) work but not addlistener(gcf,'WindowKeyPressFcn',@keyPress)? I would think that the latter would work just as well as the former, since WindowKeyPressFcn is a figure property.
> - Why does addlistener not let me pass handles? ie., addlistener(gcf,'WindowKeyPress',{@keyPress,handles}) throws an error.
> Thank you so much for your help.
> Emma

HI Emma,
On the why addlistener(gcf,'WindowKeyPressFcn',@keyPress) does not work is that you have to pass addlistener the event name not the property. Internally 'WindowKeyPress' is the event that 'WindowKeyPressFcn' is listening for.

I will have to take a quick look at the 2nd part of your question.

Some docs for addlistener can be found by typing doc addlistener

Matt W

Tags for this Thread

Everyone's Tags:

Add a New Tag:

Separated by commas
Ex.: root locus, bode

What are tags?

A tag is like a keyword or category label associated with each thread. Tags make it easier for you to find threads of interest.

Anyone can tag a thread. Tags are public and visible to everyone.

Tag Activity for This Thread
Tag Applied By Date/Time
addlistener Matthew Whitaker 18 Feb, 2010 19:49:11
pan Emma 18 Feb, 2010 18:59:06
zoom Emma 18 Feb, 2010 18:59:06
windowkeypressfcn Emma 18 Feb, 2010 18:59:06
rssFeed for this Thread

Contact us at files@mathworks.com