LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Run until keypressed

Hi.

I've created a rather large VI, which I want to run repeatedly, until a key is pressed on the keyboard.
On this Forum I've found a "press any key".vi (made by SachaE, thanks for that), which seemed really helpful at first. However, I cannot manage to change it to my needs.

I'm trying something slightly different: This 'Press any key".vi waits until keypressed, so the program is halted until you press a key.

I'd like my main VI to keep running until keypressed. So I want the key-vi to exit anyway, but with a boolean output "key pressed?", so I can attach my while loop to it. If boolean is false, then Rerun the keypress.vi and rerun my main program.

Any ideas how to do this ?

Thanks for all your help,
Michiel.

I've atta
ched the original 'press_any_key_to_continue.vi' from SachaE.
0 Kudos
Message 1 of 7
(5,072 Views)
Hello MVestjens,

two possibilities:
1) Use "Wait for Front Panel Activity" and check if the user hits a key.
2) Use Event structure to check for a keypress.

Put one of the possibilities into a while loop running
in parallel to your code and end your code, when the
user hits a key. I'm using a global stop boolean, which
is polled from any important subvi/substructure for
such cases.

Best regards
Gerd
Best regards,
GerdW


using LV2016/2019/2021 on Win10/11+cRIO, TestStand2016/2019
0 Kudos
Message 2 of 7
(5,072 Views)
Thank you for your help.

I'm not really into Event structures, so I tried the Wait for Front Panel Activity.
I find this VI to be very strange. You can select whether the VI needs to 'wait until keypressed', (option a) or 'not to wait until key pressed', and just continue. (option b)

In either case it returns a very large number, which I conclude is the current time in milliseconds.

Case
a) The Wait option.
You get no output, so the whole system is waiting on this VI to finish before it can determine whether the 'while'-condition is satisfied. When it finishes with a keypress it gives you the time the key was pressed. -> Program is 'on hold' till you press a key and then ended, because the loop condition is satisfied.

b) The don't wait
option.
You immediately get a time as a result, without even having pressed a jey. When you actually DO press a button you also get a time returned. So there is no way you can distinguish between having pressed or not having pressed a key ?

I'd suspect the 'don't wait option to return a zero when no front panel activity was recorded, but it returns a time anyway.

What am I doing wrong here ?
I've attached my simple test below.
Thanks again,
Michiel.
0 Kudos
Message 3 of 7
(5,072 Views)
Hello Michiel,

I changed your VI to reflect my description above.
When I start it on my cmputer it runs til I press a key.

Hope this helps.
Best regards
Gerd
Best regards,
GerdW


using LV2016/2019/2021 on Win10/11+cRIO, TestStand2016/2019
0 Kudos
Message 4 of 7
(5,072 Views)
Thanks again...

but is it just me or doesn't this VI exit either without a key being hit ? (returning false)

I see this VI exits only when I press a key, making the 'state' boolean true. But it doesn't exit with the key boolean false...it just reruns the while loop.

I tried to make a simple screenshot as how I'm trying to implement things, if I'm unclear. Is it impossible to create this ?

Thanks,
Michiel.
0 Kudos
Message 5 of 7
(5,072 Views)
Ok if that is what you want...
I put that into the attached vi. It's an event
structure checking for a "Key Down" event and a timeout
of 1000 ms. Change that to your needs.

Best regards
Gerd
Best regards,
GerdW


using LV2016/2019/2021 on Win10/11+cRIO, TestStand2016/2019
Message 6 of 7
(5,072 Views)
YES ! Great ! Thanks for your repeated help!

(And I see, an event structure after all. I don't understand those yet, so I'll have a look at them for future projects.)

Thanks!
Michiel.
0 Kudos
Message 7 of 7
(5,072 Views)