0

So I'm trying to make an application in C# that executes some code before one locks his/her computer with Windows Key+L.

I don't have any experience with keyboard hooks whatsoever. I searched the web and found a nice implementation of a keyboard hook: Low-Level Keyboard Hook in C#

However, since the LWin and RWin key aren't modifier keys (as far as I understand), I cannot get the above mentioned example working for my case.

Does anyone have some sources and/or examples on how I can capture the LWin+L or RWin+L key combination?

I failed to find examples or information about how to prevent windows from locking itself with the Win+L key combination too. Is this even possible? If yes, how would I be able to achieve this?

Thanks in advance!

Ixbitz
  • 427
  • 1
  • 5
  • 7
  • You are also able to the lock the computer from the ctrl+alt+del screen. Do you need to capture this event as well? – Sunshine Nov 13 '17 at 20:19
  • @Sunshine Not necessarily, but if i can somehow capture a "windows lock" event or something, that would be sufficient. – Ixbitz Nov 13 '17 at 20:52
  • https://stackoverflow.com/a/734037/7055056 Has an example of a windows service that listens for session event. – Sunshine Nov 13 '17 at 21:55

1 Answers1

0

Try this: http://inputsimulator.codeplex.com/

This sends Win32 SendInput methods to C#. This allows you to directly send the windows key. This will work:

InputSimulator.SimulateModifiedKeyStroke(VirtualKeyCode.LWIN, VirtualKeyCode.VK_L);

Adds
  • 601
  • 2
  • 12
  • 24