02-03-2017 03:04 PM
I want LAbVIEW to logout of a program if there is no keyboard or mouse activity.
Is there a simple VI to monitor when the last keyboard or mouse activity occurred? Or is this something that is available in activex?
The question was asked before but the resolution isn't really that helpful:
https://forums.ni.com/t5/LabVIEW/quit-lv-for-keyboard-inactivity/m-p/2305336#M725398
The VI quoted is this : Input Device Control\Monitoring Keyboard and Mouse Activity.vi
It has to be run continuously and loses events, for example if I put the timer to 1 second and press the keys at the wrong time, the event is lost.
Is there any VI that will just return the time of the last mouse/ keyboard event or at least one that retains the events for more than a second?
02-03-2017 04:20 PM
Try this one instead: Wait For Front Panel Activity
to avoid continous poll.
02-03-2017 04:40 PM
Thanks George,
That's almost what I need, except I need it to occur in an event timeout that needs to keep running.
If there was anyway it could just report the time of the last event it would be ideal.
Rgds,
Seán
02-04-2017 08:51 AM
I just tried wait for front panel activity and it is worse than I expected.
Moving the mouse does not produce and event nor does clicking on an area that is not a control/ indicator.
Basically, I am looking for the same functionality as a screensaver. Any ideas?
02-05-2017 01:07 PM
I think that functionality is buried somewhere within Windows. Maybe a Web Search would locate this -- try using "Windows Screensaver" or "How to start Screensaver" as a topic.
Bob Schor
02-05-2017 03:55 PM
Create an event structure with three events: one to watch the mouse, one to watch keys, and a timeout with your desired wait wired into the event structure.
Then, any time you move the mose or hit a key, you trigger an event. The loop cycles back. If it ever reaches timeout, neither the mouse nor keyboard were hit. You don't need to know the last time they were hit. The timeout handles that for you.
02-05-2017 04:18 PM
Hi Bob,
Thanks for that, this actually looks like it might be what I need:
https://www.autohotkey.com/docs/Variables.htm#User_Idle_Time
I'll get back if I actually get it working, (for the time being I've just introduced another loop which is not ideal).
05-15-2020 05:37 AM
This can be a way to find the inactivity in mouse an keyboard.
05-15-2020 07:54 AM - edited 05-15-2020 07:58 AM
@Rajansh wrote:
This can be a way to find the inactivity in mouse an keyboard.
True, but you are polling again, and I would (almost) always choose an event-driven solution over a polling solution. An extreme example of polling vs event-driven code can be seen when modding with scripts for some games. Running a script that continuously polls certain variables can actually cause the game to crash, whereas waiting on an event that would change that same variable gives the game engine a break.
04-24-2024 03:58 PM - edited 04-24-2024 03:59 PM
I have modified your program and tried it like this. It works perfectly for key and mouse inactivity with low refresh rate. Every key stroke and mouse movement is detected 100 %