LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

How do I get keyboard events when window is not active

I'd like to get keyboard events (key up, key down) even when the front panel isn't active (for example if it's minimized or if another window pops up and steals focus). I saw one thread and the suggestion was to use Acquire Input Data. That seems viable but I'd rather not poll if I didn't have to. I also saw a suggestion to use the Windows Message Queue Library but it looks like it might be broken in LV64.

 

Any other suggestions?

0 Kudos
Message 1 of 29
(4,035 Views)

Only the active window gets notified by OS.

 

George Zou
0 Kudos
Message 2 of 29
(4,019 Views)

@nanocyte wrote:

I also saw a suggestion to use the Windows Message Queue Library but it looks like it might be broken in LV64.


That shouldn't be hard to fix though. Replacing all 32 bit pointers with pointer sized integers should do the trick. With a little care it should work for 32 bit and 64 bit.

 

But if you're going to hook a window, you might still not get events if it's not active. I didn't catch up with recent versions on this. LabVIEW used to have one handler for all windows.

0 Kudos
Message 3 of 29
(3,970 Views)

@zou wrote:

Only the active window gets notified by OS.

 


You're saying Windows Message Queue Library won't work? Oh, I hope I don't have to hook into a driver.

0 Kudos
Message 4 of 29
(3,940 Views)

But if you're going to hook a window, you might still not get events if it's not active.

> I didn't catch up with recent versions on this. LabVIEW used to have one handler for

> all windows.

 

You have to implement a system wide hook, i.e. inject your hook dll into all processes, not just a window.

 

 

George Zou
0 Kudos
Message 5 of 29
(3,927 Views)

I believe it's meant to be hard. That's how you make keyloggers ...

/Y

G# - Award winning reference based OOP for LV, for free! - Qestit VIPM GitHub

Qestit Systems
Certified-LabVIEW-Developer
Message 6 of 29
(3,922 Views)

@zou wrote:

But if you're going to hook a window, you might still not get events if it's not active.

> I didn't catch up with recent versions on this. LabVIEW used to have one handler for

> all windows.

 

You have to implement a system wide hook, i.e. inject your hook dll into all processes, not just a window.


Not per se. There is a level between "system wide" and "when the window is not active". OP might want to monitor keystrokes in LabVIEW, while the VI that monitors is not active.

 

In fact, if that is the case, (s)he can do so with normal LabVIEW events by dynamically registering for other VI's events.

 

Guess OP has some explaining to do.

Message 7 of 29
(3,918 Views)

Apparently, you can register a systemwide hot key: registerhotkey (MSDN). But that only catches one key, and you'll get a window message as a result. So you'd still need to hook the window handler.

 

It's all about details, but polling looks pretty good compared to hooking messages. Globally or not.

Message 8 of 29
(3,913 Views)

@Yamaeda wrote:

I believe it's meant to be hard. That's how you make keyloggers ...

/Y


That makes no sense. I can always just poll for your keys with Acquire Input Data so I don't think this is "hard" per se. It's really just a matter of implementation at this point.

0 Kudos
Message 9 of 29
(3,898 Views)

Not per se. There is a level between "system wide" and "when the window is not active". OP might want to monitor keystrokes in LabVIEW, while the VI that monitors is not active.

 

In fact, if that is the case, (s)he can do so with normal LabVIEW events by dynamically registering for other VI's events.

 

Guess OP has some explaining to do.


When the user presses an arrow key I want to start an action and then when they lift up off the arrow key I want to stop that action. There's an issue right now where if another window pops up while the user is pressing the arrow, LV doesn't get the key down event and the action continues indefinitely.

Message 10 of 29
(3,895 Views)