LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

conditionally monitor keypresses based on LabVIEW being the in-focus app in Windows

Solved!
Go to solution

Hi all,

 

I'm using LV 2009 in Vista.  I am using a dynamic VI, in addition to the top-level, to monitor the keyboard for key presses.  It works great except for the fact that when I have another app open while the LabVIEW app is running, it still responds to the key press.  i.e.  While using the calculator and pressing the ESC key to clear the display, LabVIEW reacts as well.

 

Can LabVIEW find out if it's the "focus app" in the windows environment?  I know it can tell which of it's windows are in front, but what about other apps?  I'm thinking of using this to filter out key presses when LV is not the front application.

 

Thank you!

Charlie

 

0 Kudos
Message 1 of 8
(3,174 Views)

Why would you use a dynamic VI? You could also use the event structure to monitor for key down events on front panels. That would make sure a LbVIEW VI is in the front.

 

I have written an extensive post on dynamically checking for events here.

 

Ton

Free Code Capture Tool! Version 2.1.3 with comments, web-upload, back-save and snippets!
Nederlandse LabVIEW user groep www.lvug.nl
My LabVIEW Ideas

LabVIEW, programming like it should be!
0 Kudos
Message 2 of 8
(3,169 Views)

Ah....  I neglected to mention that I am locked into the Base version of LabVIEW, so no Event Structure.  Though I am working on changing that...   😉

 

I'm using a dynamic VI because it is functioning as something of an E-stop.  I need it to operate independently of the main program.

 

-Charlie

 

 

 

0 Kudos
Message 3 of 8
(3,164 Views)

Hi Charlie

 

Maybe this setup attached will work for you.

I've used a Call Library Function Node to get the Windows Handle for the window in the foreground. When you start your application this should return the handle for your application, then you simply use the same call and compare the current handle to the first handle.

If they are the same do your key logging. 

If they are different don't do anything.

 

<Brian Aswege | Applications Engineering | National Instruments> 

 

 

0 Kudos
Message 4 of 8
(3,119 Views)

Hi Brian,

 

Thanks for the VI.  Unfortunately, it won't open in my version of LabVIEW (2009).

 

Could you save to previous version and repost?

 

Thanks!

Charlie

 

 

 

 

0 Kudos
Message 5 of 8
(3,071 Views)
Solution
Accepted by topic author asuwish4

Here is the vi saved as a 2009 vi 

<Brian Aswege | Applications Engineering | National Instruments> 

Message 6 of 8
(3,035 Views)

Thanks Brian!

 

The VI I use to monitor the key-presses is dynamically-called, so I put the call in the top-level, feeding a functional global the value.  The error out connects to the VI Reference that calls the monitor that uses the same call in a loop, constantly checking against the FuncGlob.

 

Thanks again!

Charlie

 

 

 

0 Kudos
Message 7 of 8
(3,024 Views)

After reading my last post, it seems confusing in text form Smiley Wink

 

Here are some snips:

 

 

This is in the top-level vi.  This code occurs before the main loops start...

TopLevel.JPG
This gets the window handle for the top-level front panel

 

 

Then this code occurs in the dynamically-called LTS_Escape Key Handler.vi....

Dynamic.JPG
This just compares the current Foreground window handle to the one stored in the FG.

0 Kudos
Message 8 of 8
(2,977 Views)