0

I am writing a windows forms application in Visual Basic, and I would like to know how to execute some code when any key is pressed in any window. I have tried onkeypressed, but that only works in the form, and I want to have it system-wide. Can anyone help? I'm pretty new to VB, but I know the basics...

Thanks, Matt

Visual Vincent
  • 18,045
  • 5
  • 28
  • 75
  • My program is not in the background (although it might be later, but not now) and I want to do something when ANY key is pressed. Not just Mod + O – UltraLuminous Oct 29 '16 at 14:53
  • It works in the foreground too. "Background" refers to any time neither of your windows are focused (and you did say system-wide, so...). So you want to capture _any_ set of keys, and not just predefined ones? Somewhat like a keylogger? – Visual Vincent Oct 29 '16 at 14:56
  • Somewhat I guess. But it wont be a keylogger, don't worry :D – UltraLuminous Oct 29 '16 at 14:57
  • Oh, well the question I linked to is mainly to be used for hotkeys (sorry for not understanding your request), then what you need is a [system-wide keyboard hook](http://stackoverflow.com/a/15038869/3740093). – Visual Vincent Oct 29 '16 at 14:59
  • Thanks so much, that should do it! Add it as an answer,.and I will mark it as solved. – UltraLuminous Oct 29 '16 at 15:01
  • Link-only answers are generally discouraged. You can flag/close your question as a duplicate of the one I just linked you to instead. – Visual Vincent Oct 29 '16 at 15:02
  • Okay... I'll try that. – UltraLuminous Oct 29 '16 at 15:03
  • Possible duplicate of [How to listen keyboard in background and fire keystrokes on demand?](http://stackoverflow.com/questions/15038413/how-to-listen-keyboard-in-background-and-fire-keystrokes-on-demand) – Andrew Morton Oct 29 '16 at 16:54

0 Answers0