Login  Register

Key Pressed and moving an Roi around in a ImageWindow

Posted by Fred Damen on Aug 30, 2020; 6:53pm
URL: http://imagej.273.s1.nabble.com/Key-Pressed-and-moving-an-Roi-around-in-a-ImageWindow-tp5023893.html

Greetings,

A while back I asked why sometimes hitting the up or down arrows in an
ImageWindow would cause the contained Roi to move up and down, and
sometimes the ImageWindow would zoom up(+) or down(-).  It turns out that
the ImageJ.keyPressed method is a low level I/O method, and as such, gets
called on every key pressed, including modifiers.
ImageJ.keyPressed/keyReleased stores the current state of the modifier
keys.  Unfortunately, if a modifier key is pressed in a ImageJ window and
then released while not in a ImageJ window, the current modifier status
may not reflect the actual current status. In my case, if the control or
shift key is pressed while in an ImageJ window and released outside and
ImageJ window, then upon hitting the up or down arrows in a ImageWindow
the zoom cmd would be run instead of the roi.nudge method being called.

Previously, I had noticed that requesting a image to be duplicated, and
then canceling, cleared this anomaly. It turns out that all you have to do
is, within the ImageWindow press and release the shift, and then the
control, keys to clear this anomaly.  It seems obvious now, but it stumped
me for a long time; so hopefully knowing this will help others.

I suspect, but have not tested, that calling KeyEvent.isShiftDown and
KeyEvent.isControlDown methods instead of IJ.shiftKeyDown() and
IJ.controlKeyDown may alleviate this issue.

Thanks,

Fred

--
ImageJ mailing list: http://imagej.nih.gov/ij/list.html