Solved

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

Posted on 2009-05-08
4
900 Views
Last Modified: 2013-12-17

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
Comment
Question by:baijajusav
  • 2
4 Comments
 
LVL 8

Assisted Solution

by:mac-will
mac-will earned 400 total points
Comment Utility
0
 
LVL 3

Author Comment

by:baijajusav
Comment Utility

That's probably exactly what I need. I'll test over the weekend to verify.
0
 
LVL 3

Accepted Solution

by:
baijajusav earned 0 total points
Comment Utility
0
 
LVL 85

Assisted Solution

by:Mike Tomlinson
Mike Tomlinson earned 100 total points
Comment Utility
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

Free Trending Threat Insights Every Day

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

Join & Write a Comment

Suggested Solutions

Many of us here at EE write code. Many of us write exceptional code; just as many of us write exception-prone code. As we all should know, exceptions are a mechanism for handling errors which are typically out of our control. From database errors, t…
Exception Handling is in the core of any application that is able to dignify its name. In this article, I'll guide you through the process of writing a DRY (Don't Repeat Yourself) Exception Handling mechanism, using Aspect Oriented Programming.
Excel styles will make formatting consistent and let you apply and change formatting faster. In this tutorial, you'll learn how to use Excel's built-in styles, how to modify styles, and how to create your own. You'll also learn how to use your custo…
Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…

744 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

16 Experts available now in Live!

Get 1:1 Help Now