Do Something while key is pressed AND held down


Here is the problem I am trying to solve.
I want to present a folders worth of images (~1000-6000) to a user basically as fast as possible and when they see a change in the image stop and flag the change and then proceed.

Today I am using a window hook to present the next image, but that requires a key press and release to work. For example I use the return key to load the next image. If I hold the return down, only the single next image is loaded and then it waits for me to release the key.

Is it possible (or a better phrase how is possible) to keep loading images while a key is pressed and then stop when released?


As near as I remember, key captures can work on a key down or a key up event. Also, when you return a 1 from the hook, this shuts down any future pass back thru that same hook function. So, if I had to guess, I would say that you should ...

* capture the keystroke on the down
- do the actions to advance the frame (and DoUpdate to refresh all windows)
- (pause 3 seconds for user review)
- return a code 0 to allow the hook to remain active
* capture the keystroke on the up
- return a code 1 to shut off the hook function

J. J. Weimer
Chemistry / Chemical & Materials Engineering, UAH
Why not have button which starts the slide show, and in the window hook you can check if ESC was pressed, stop the slideshow, and continue on button click. Alternatively I've made good experience with using the mousewheel for scrolling through an image stack.
Jeff is right about not running a loop in your hook function. You will need to keep a global that identifies which image was last seen, and to return after each key is seen.

Unfortunately, Jeff is not right about "capturing the key release" because Igor doesn't send you separate key press and key release events. However, your hook function will be called repeatedly if you press and hold until the key repeat starts. But you have to return from the hook so that it can be called again.

And, yes, you probably want to return non-zero from the hook function to make sure Igor doesn't do anything with the keystrokes, like de-focussing the graph window and activating the command window. To avoid that problem, you could use an image subwindow in a panel, but better to return non-zero.

John Weeks
WaveMetrics, Inc.
Andy, perhaps you could make use of the Scroll Traces package.

It allows for plug-in modules. All that would be needed is to have a module to advance the image. If nothing else, it would show you how I handeled keystroke events through the panel input.

J. J. Weimer
Chemistry / Chemical & Materials Engineering, UAH