keyDown - keys interface plugin for ImageJ

Authors: François GANNIER (gannier at univ-tours dot fr) - Côme PASQUALIN University of Tours (France)
See also: Others productions for ImageJ from the authors
PCCV group main page
History: 2017/04/07: 0.1 - First version
Source: Link to GitHub.
Requires: Tested on ImageJ 1.51g but should works on older.
Limitations:Should works on Mac OS, Linux and Windows
Installation:Download and copy keyDown.jar in the jars folder then restart ImageJ.
Description:When you need using keys on keyboard in macros, ImageJ is limited to only 3 keys : "space", "alt" and "shift". This plugin is provided to extend this capabilities to all keys pressed on keyboard.
More:
- key trapped can be redirected to ImageJ or not.
- A mask can be used to not trap all keys
Usage:Usage of this plugin is very easy but a image must be opened then a value of the key pressed is returned by the function call. Visit this site to see correspondance of the returned values.
Example to trap the ESC key: when you press the ESC key, ImageJ quit abruptly the running macro. This example show how to trap the ESC key to add an action before quiting.

	// be sure an image is opened
	id = getImageID();
	selectImage(id);
	
	//flush keyboard buffer
	call("keyDown.flush");
	
	// endless loop
	while (true) {
		// be sure image is always opened
		if (!isOpen(id)) break;
		// trap keys only when image id is active, return only ESC key and pass others keys to ImageJ
		val = call("keyDown.get", id, 1);
		if (val == 27) { // ESC is pressed : this is now the only way to exit except closing the window
			save();
			// restore previous keylistener
			call("keyDown.restore",id);
			break;
		}
		// others actions to do in the loop
	}

Mask: A mask can be define to not trap all key pressed but ESC (27) is always trapped :

	mask = 1+2+16; // SPACE and NUMPAD numbers
	val = call("keyDown.get",mask);
	// here only the spacebar and numbers on the numpad are trapped
1 : key not in the mask is redirected to ImageJ (0 don't)
2 : SPACE
4 : 0-9
8 : a-z
16 : 0-9 (NUMPAD)
32 : PGUP, PGDN, Home, End + Arrow pad
64 : F1-F12
128 : NUMPAD operator
Try it: Try it with a macro toolset . Download testKey.ijm and copy it into the "ImageJ\macros\toolsets" folder.
Open an image, choose the testKey toolset, click on it and press some keys (note the window of the image must be active). In this macro only the arrow keys are trapped (you get the corresponding numbers) and you can exit only with ESC key. At the same time, if you open another image, normal keys from ImageJ are used. you could change the mask (currently 1+64) to activate more keys.

|Plugins | Home |