Solved

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

Posted on 2009-05-08
4
901 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
ID: 24338830
0
 
LVL 3

Author Comment

by:baijajusav
ID: 24338901

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
ID: 24339187
0
 
LVL 85

Assisted Solution

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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article describes relatively difficult and non-obvious issues that are likely to arise when creating COM class in Visual Studio and deploying it by professional MSI-authoring tools. It is assumed that the reader is already familiar with the cla…
This document covers how to connect to SQL Server and browse its contents.  It is meant for those new to Visual Studio and/or working with Microsoft SQL Server.  It is not a guide to building SQL Server database connections in your code.  This is mo…
Sending a Secure fax is easy with eFax Corporate (http://www.enterprise.efax.com). First, just open a new email message. In the To field, type your recipient's fax number @efaxsend.com. You can even send a secure international fax — just include t…
With the power of JIRA, there's an unlimited number of ways you can customize it, use it and benefit from it. With that in mind, there's bound to be things that I wasn't able to cover in this course. With this summary we'll look at some places to go…

863 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

26 Experts available now in Live!

Get 1:1 Help Now