0

I wish the user to be able to press the Ctrl, and my form does something and upon releasing this key, the form does something else. Unfortunately, my form may not be in focus (nor the foreground window). How can I achieve this? I'm guessing it's a PInvoke, but a search didn't turn up anything obvious.

Thanks Thomas

friartuck
  • 2,954
  • 4
  • 33
  • 67
  • PInvoke is for calling functions from unmanaged dll's, nothing to do with keyboardhooks – Jeroen van Langen Feb 05 '15 at 07:25
  • It maynot be possible directly from forms. But possible with windows hooks. Refer [this](http://stackoverflow.com/questions/17056235/how-to-get-keyup-keydown-keypress-events-on-a-windows-forms-form-that-is-minimiz) – LakshmiNarayanan Feb 05 '15 at 07:29
  • Hi Jeroen, I'm aware of that :) I meant in the sense that I'm going to have to go the route of invoking some native dll methods (user32.dll no doubt) to get the functionality I'm after – friartuck Feb 05 '15 at 07:30

1 Answers1

0

You need to use SetWindowsHook for this. You application will get a callback when the keyboard is triggered.

You should checkout this example code: http://blogs.msdn.com/b/toub/archive/2006/05/03/589423.aspx

Jeroen van Langen
  • 21,446
  • 3
  • 42
  • 57