Printable Version of Topic

Click here to view this topic in its original format

Dream.In.Code _ C# _ Controlling non selected application with key events

Posted by: handshaker 2 Jul, 2009 - 07:14 AM

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?

Posted by: MageUK 2 Jul, 2009 - 07:58 AM

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.

Posted by: handshaker 2 Jul, 2009 - 10:10 PM

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.

Powered by Invision Power Board (http://www.invisionboard.com)
© Invision Power Services (http://www.invisionpower.com)