LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

How to determine if Windows Screen has been locked?

Solved!
Go to solution

I have a program that runs in the background.

I would like to change the behavior of the code if the screen has been locked (windows-L)

 

How can I find out if the screen has been locked?

 

0 Kudos
Message 1 of 10
(4,434 Views)

.NET system events will send a signal.

 

You'll need to use a callback VI, but you can put a user event in it to make the callback VI send a user event to a normal event structure.

System Event.png

 

I think you need SessionSwitch, and then examine the SessionSwitchReason (lock or unlock).

Message 2 of 10
(4,405 Views)
Solution
Accepted by topic author RustyStrings

Just a quick and dirty example. It needs work, but shows the principle...

Download All
Message 3 of 10
(4,397 Views)

Thank you for replying to my qestion.

Just like many times the answer cause more questions.

This is a type of LabVIEW programming that is unfamiliar to me.

I tried to create the callback vi but I have no idea what the event data should be

 

My only experience with callbacks has been with TestStand operator interface code and I did not know they were even used elsewhere.

 

If it is not too much trouble can you demo a dummy callback vi that would connect to this registered even?

 

Thanks

0 Kudos
Message 4 of 10
(4,384 Views)

You must have been sending this as I was typing my question.

 

0 Kudos
Message 5 of 10
(4,379 Views)

I was able to add this to my code, and get it to work.

It seems to me that when the screen is locked the event will generate a 7, and when the screen is unlocked it generates an 8.

 

Thanks 

 

P.S.

Now I know about (aware of) something else that I don't know about..

0 Kudos
Message 6 of 10
(4,372 Views)

You're welcome.

 

Those callbacks are pretty uncommon. They can be great, you can also wire regular LabVIEW control references to them. Then right click to create the callback with the required prototype. They are great because they can implement filters and such, but data is a problem. Since they are started once, it's hard to get them to use actual\current data. You need DVR's or buffers. The great thing is you don't have to stop them. They stop automatically when the calling VI stops. For .NET and ActiveX they are the only way to get events...

0 Kudos
Message 7 of 10
(4,341 Views)

The solution you have provided will work by catching the event when the screen is locked or unlocked.

Is there a way to poll/query for the state of the the locked screen?

 

Also in a side not for the life of me I can't figure out how to put a LabVIEW control refence on the block diagram connected to the Reg Event Callback and right click on it to make the callback vi with the correct prototype

 

 

0 Kudos
Message 8 of 10
(4,307 Views)

@RustyStrings wrote:

The solution you have provided will work by catching the event when the screen is locked or unlocked.

Is there a way to poll/query for the state of the the locked screen?


No easy way as far as I can tell. I'll dig around a bit (I'm sure I did it at some point).

 


@RustyStrings wrote:

Also in a side not for the life of me I can't figure out how to put a LabVIEW control refence on the block diagram connected to the Reg Event Callback and right click on it to make the callback vi with the correct prototype 


 On a terminal (or control) right click and select Create>Reference. Wire it to the Register Event Callback. Then select an event. Then, right click the RECN and select create callback. Pretty sure the last step is disabled when no valid reference is wired or when no event was selected.

0 Kudos
Message 9 of 10
(4,301 Views)

It is amasing how you can miss something right in front of you.

 

I see now that all I had to do was right click on the Reg Event Callback at the VI Ref location and Create Callback is an option.

I think I was expexting it to be a sub menu of the create menu.callback.PNG

 

Thanks for you help !

Message 10 of 10
(4,294 Views)