2 Replies - 676 Views - Last Post: 02 July 2009 - 11:10 PM Rate Topic: -----

#1 handshaker  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 6
  • Joined: 02-July 09

Controlling non selected application with key events

Posted 02 July 2009 - 08: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?
Is This A Good Question/Topic? 0
  • +

Replies To: Controlling non selected application with key events

#2 RudiVisser  Icon User is offline

  • .. does not guess solutions
  • member icon

Reputation: 1004
  • View blog
  • Posts: 3,562
  • Joined: 05-June 09

Re: Controlling non selected application with key events

Posted 02 July 2009 - 08: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.

This post has been edited by MageUK: 02 July 2009 - 09:00 AM

Was This Post Helpful? 1
  • +
  • -

#3 handshaker  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 6
  • Joined: 02-July 09

Re: Controlling non selected application with key events

Posted 02 July 2009 - 11: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.
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1