Waitforuser press a key

macro
Tags: #<Tag:0x00007fd699c73658>

#1

Hi Everyone,

We know about the waitforuser function, where we have to click the “OK” button to continue. Is it possible to continue by pressing a spacebar or some other key (or there is a function available which can do this)?

I am aware that using Java it is possible (like in Java "press space bar to continue"), but I am seeking something that can be implemented using IJ macro programming.

Thanks in advance.


#2

@Jpp

Sorry for the delay in response - so I’m not sure this will answer your question… but I was perusing the Built-In Macro Functions page and found this guy:

isKeyDown(key)
Returns true if the specified key is pressed, where key must be “shift”, “alt” or “space”. See also: setKeyDown.

Perhaps you can use this function with an if statement or so within your code? Hope this helps a little in any case…

eta


#3

Dear @Jpp,

Something like the following should work (at least is has worked in my short tests):

// Do something
// Wait for input:
while (!isKeyDown("shift")) {
    wait(10);
}
// Do something after Shift was pressed

And thanks @etarena for bringing isKeyDown() back to my attention. Had already forgotten about that :wink:

Best,
Stefan