Java "press space bar to continue"

Hi Forum,

I’ve got a question about java programming. I’m busy with a program which does some analysis. However, half-way I’ve to select some ROI with the multi-point tool. After I’ve done this, I would like to press a key, so the code will continue.

I know that the waitforuserdialog class has the option to add a keyevent. However, I can’t find anything about passing the keyevent to “press the spacebar”.

I could also find stuff about keylisteners, but I don’t know what to do exactly. Hopefully you can help me out.

My draft at this moment;

``public class test{
private ImagePlus img;

//do stuff with processing the image

public void action(KeyEvent e){
if (e.getKeyCode()==KeyEvent.VK_SPACE){
//do stuff

Who can help me out?

Hi @NoUsername,

It looks like you’re very close… The final hint is to add “this” object as a KeyLIstener.
Check out this example (with, I think, the most relevant line for you highlighted):

Hope this helps, and please reply if anything is still unclear.


Thanks a lot! It worked out very well. I’m relieved with the results :smiley:

Great, glad to hear it worked!