C# School Assignment? Project Due Tomorrow? Chat LIVE With A Programming Expert!

Welcome to Dream.In.Code
Become a C# Expert!

Join 300,437 C# Programmers for FREE! Get instant access to thousands of C# experts, tutorials, code snippets, and more! There are 1,478 people online right now. Registration is fast and FREE... Join Now!




Controlling non selected application with key events

 

Controlling non selected application with key events

handshaker

2 Jul, 2009 - 07:14 AM
Post #1

New D.I.C Head
*

Joined: 2 Jul, 2009
Posts: 6

Hi fellas,
I wanna make a program that is sensitive to the keys when its window is non selected. Its like some music player's global hotkeys. When im using another application, if i press a key my program must react. How can i do this? Does backgroundworker work for this? What do you advice me to use?

User is offlineProfile CardPM
+Quote Post


RudiVisser

RE: Controlling Non Selected Application With Key Events

2 Jul, 2009 - 07:58 AM
Post #2

.. does not guess solutions
Group Icon

Joined: 5 Jun, 2009
Posts: 1,872



Thanked: 137 times
Dream Kudos: 125
Expert In: PHP, MySQL, HTML, CSS, C#

My Contributions
You should use a thread that checks GetAsyncKeyState, that works globally (application-wise) so you should use it to check for the hotkeys that you would like to use.

I heard of a "Global Keyboard Hook" using SetWindowsHookEx at one point, but GetAsyncKeyState would be much easier, imo.

This post has been edited by MageUK: 2 Jul, 2009 - 08:00 AM
User is offlineProfile CardPM
+Quote Post

handshaker

RE: Controlling Non Selected Application With Key Events

2 Jul, 2009 - 10:10 PM
Post #3

New D.I.C Head
*

Joined: 2 Jul, 2009
Posts: 6

Thanks bro. Can you give an example written in c#
i imported the method by this way:

[DllImport("user32.dll", CharSet = CharSet.Auto, ExactSpelling = true)]
public static extern short GetAsyncKeyState(int vkey);

However I can't use it in program correctly.
User is offlineProfile CardPM
+Quote Post

Fast ReplyReply to this topicStart new topic

Time is now: 11/8/09 01:06AM

Live C# Help!

Be Social

Dream.In.Code RSS Feed Dream.In.Code LinkedIn Group Follow Us On Twitter Fan Us On Facebook

C# Tutorials

Reference Sheets

C# Snippets

DIC Chatroom

Bye Bye Ads

Monthly Drawing

Thumb Drive

Top Contributors

Top 10 Kudos This Month