2

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?

3

1 Answer 1

0

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

Sign up to request clarification or add additional context in comments.

2 Comments

Can you comment a little on this? Will it work with any application playing the e.g. music? Will it work without a MMKeyboard ? I tried and it seems to do nothing..
Oh well, checking out Hans' post it seems this is not that easy..

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.