Re: Intercepting keystrokes in plugin
Posted by
Wayne Rasband on
Jul 23, 2009; 4:31am
URL: http://imagej.273.s1.nabble.com/Intercepting-keystrokes-in-plugin-tp3691678p3691680.html
> Hello Imagers,
>
> I wrote a plugin a long time ago (for browsing 4d datasets from disc)
> that extends the ImageWindow class, and creates a KeyListener to act
> on the up, down, left, and right arrow keys. This worked well before
> the default behavior was to magnify or reduce the ImageWindow using
> the right and left arrow keys, as in more recent versions of ImageJ.
> Now the plugin reads the key stroke and acts on it, but the key stroke
> is passed to ImageJ, which then magnifies or reduces the ImageWindow.
> I guess I'm stupid, but I don't see how to prevent this.
>
> Any ideas would be deeply appreciated!
You can keep key pressed events from being passed to ImageJ by
removing it as a KeyListener using
removeKeyListener(IJ.getInstance());
I updated the KeyListener example plugin at
http://rsbweb.nih.gov/ij/plugins/key-listener.htmlto do this. I tried using KeyEvent.consume() but it didn't work
because the plugin's keyPressed() method was called after ImageJ's
keyPressed() method.
-wayne