Go Premium for a chance to win a PS4. Enter to Win

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 922
  • Last Modified:

How to detect key strokes in c# when my application is not active?


I'm working on a custom clipboard manager. I pretty much want an app that replaces the windows clipboard with one that can store multiple instances of text, images, and/or files. The general idea is this will be a windows C# application (probably written with Visual C# 2008 Express Edition) where it will namely reside in the system tray and have no active window. I want to be able to use a specific key combination to pull up the active window for this application I'm creating. I don't want to bother with moving the mouse around or all that.

I guess it boils down to needing to be able to check all keystrokes against the specific combination setup for my application regardless what window is acting.

I've found some articles that discuss this in a broad manner but I'm really trying to get some code for this. Any help you can provide would be greatly appreciated. Thanks!
0
baijajusav
Asked:
baijajusav
  • 2
3 Solutions
 
baijajusavAuthor Commented:

That's probably exactly what I need. I'll test over the weekend to verify.
0
 
baijajusavAuthor Commented:
0
 
Mike TomlinsonMiddle School Assistant TeacherCommented:
Right...you basically only have three options:  (all involving external WinAPIs)
(1) Trap ALL keystrokes with a low level keyboard via WH_KEYBOARD_LL.
(2) POLL the keyboard with a Timer and the GetAsyncKeyState() API.
(3) Register your desired key combo as a system wide hotkey via RegisterHotkey().  This is the least resource intensive BUT only one process can register a unique key combo.  If another app has already taken your combo then you have no recourse but to pick another one or use methods #1 or #2 instead.
0

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now