'global' key events ?

Good [insert word according to your daytime] to you,

when I have a UserControl on my form, and there are some controls placed onto my UserControl, the thing no more receives key events.
My UC needs to be notified whenever the Ctrl key just got released.

So, is there a way to receive key events independently from the focused control

I could engage an extra thread to keep an eye on all keys of which I need to know about their activities, and invoke a delegate to the handler function if a keystate has changed,
but this seems like a kind of too-big gun I'd say . . . or not


Answer this question

'global' key events ?

  • KewlKid87

    I've read about event hooks, but, apart from me not being entirely sure yet whether this is what I'm looking for, it's an even bigger gun.
    I've also read that these event hooks can slow down the system . . . hey I just want to monitor KeyUp event's, I think slowing down the system for that silly little purpose is not quite justified . . .
    But if there's no built-in way to do what I want, I guess I'll have to use either this, or the watchdog thread. I'm biased towards the latter.

  • No FREE

    Steve#2,

    Yes, event hooks are your answer. You need to use Win32 calls to create them and register them. They are processed before messages go to the application. You can create one for most win msgs such as keyboard, mouse, clipboard, etc. When I made one for the clipboard, I think I found a good example at codeproject. 

    You're right that it slows the system down. But it's performance is better than running your own thread and polling for key presses. It's really just another case in a switch statement right before the message gets sent to the application. If you put a hook on a mouse, that could be slow. But a keypress is not a big deal. 

    Good luck.


  • 'global' key events ?