I am trying to detect the Print Screen
button press while the form is not the current active application.
How to do that, if possible?
I am trying to detect the Print Screen
button press while the form is not the current active application.
How to do that, if possible?
The API
GetAsyncKeyState()
may be a perfectly acceptable alternative to setting up Windows Hook.This depends on how you desire to receive the input. If you prefer event-driven notifications, then a hook is the way to go; however, if you prefer polling the keyboard for state changes, you can use the API above.
Here is a simple demonstration of how to use
GetAsyncKeyState
:Derived from Pinvoke.NET
Yes you can, it's called "System hooks", take a look at Global System Hooks in .NET.
Well, if you had problems with System hooks, here is ready-made solution (based on http://www.dreamincode.net/forums/topic/180436-global-hotkeys/):
Define static class in your project:
Define class in your project:
add usings:
now, in your Form, add field:
and in Form constructor:
Add those 2 methods to your form:
HandleHotkey is your button press handler. You can change the button by passing different parameter here:
ghk = new KeyHandler(Keys.PrintScreen, this);
Now your program reacts for buton input even if not focused.