I'm making an app that will pause/play music on an event. I am not making my own music player, rather I'd like to use the universal pause/play that windows has System wide. Is there any way to do this?
- The Multimdia Keys are part of the Key enumeration.TaW– TaW2017-01-29 12:30:45 +00:00Commented Jan 29, 2017 at 12:30
- 1See if any of these post help you: Send key “MediaPlayPause”, Send keys through SendInput, Send multimedia commands, Codes of multimedia keys - Please report if anyone does help and maybe post the solution and an answer!TaW– TaW2017-01-29 12:40:41 +00:00Commented Jan 29, 2017 at 12:40
- Reading through all this, it seems making your own player is simpler after all..TaW– TaW2017-01-29 15:53:16 +00:00Commented Jan 29, 2017 at 15:53
Add a comment |
1 Answer
You'll have to use the keybd_event windows API to do this.
using System.Runtime.InteropServices; ... [DllImport("user32.dll")] static extern void keybd_event(byte bVk, byte bScan, uint dwFlags, UIntPtr dwExtraInfo); public const int KEYEVENTF_KEYUP = 0x0002; public const byte VK_MEDIA_PLAY_PAUSE = 0xB3; private void button_Click(object sender, RoutedEventArgs e) { // No flags indicate key down keybd_event(VK_MEDIA_PLAY_PAUSE, 0, 0, UIntPtr.Zero); keybd_event(VK_MEDIA_PLAY_PAUSE, 0, KEYEVENTF_KEYUP, UIntPtr.Zero); } For a full list of key codes, you can use this class:
https://github.com/johnkoerner/KeyboardListener/blob/master/KeyboardListener/Keycodes.cs