Wednesday, April 20, 2011

How do i send a VK_MEDIA_NEXT_TRACK in C#?

Yeah, the title almost says all. I found many things googling, but none I could actually use, so I'm just searching for a simple method, if that is possible.

Thanks.

From stackoverflow
  • The gist of the problem is that you must PInvoke into native code in order to use these methods. PInvoke is a pretty big topic and I suggest reading up on it a bit.

    Luckily though most things which can be PInvoke'd at this point have samples available on the web. For instance, take a look at the following article on CodeIdol. It gives a full winforms sample on how to use this key and many others in a c# application.

    http://codeidol.com/csharp/csharpckbk2/Delegates,-Events,-and-Anonymous-Methods/Using-the-Windows-Keyboard-Hook/

    Samuel : Your link is about hooking into the input chain to be notified about input, he wants to send input.
  • JardPar is correct, you will have to PInvoke to send the VK_MEDIA_NEXT_TRACK key. You can use the user32.SendInput function to achieve this. Take a look at pinvoke.net: SendInput (user32).

  • I've had better luck with keybd_event in the past. The method definition should look like this:

    [DllImport("user32.dll")]
    public static extern void keybd_event(byte vkCode, byte scanCode, int flags, IntPtr extraInfo);
    
  • Thank you for your answers! Maybe this evening im able to see which one works for me best.

0 comments:

Post a Comment