Skip to content

Instantly share code, notes, and snippets.

@theuntitled
Created November 30, 2015 16:10
Show Gist options
  • Save theuntitled/3f6e4b836a47e6b27c18 to your computer and use it in GitHub Desktop.
Save theuntitled/3f6e4b836a47e6b27c18 to your computer and use it in GitHub Desktop.
Send Media Hotkeys with C#
using System.Runtime.InteropServices;
using System.Windows.Forms;
namespace MediaHotkeys
{
internal class Program
{
[DllImport("user32.dll", SetLastError = true)]
private static extern void keybd_event(byte bVk, byte bScan, int dwFlags, int dwExtraInfo);
private static void Main()
{
var KEYEVENTF_KEYUP = 0x0002;
//var mediaPlayPause = (byte) Keys.MediaPlayPause;
//var mediaNextTrack = (byte) Keys.MediaNextTrack;
var mediaPreviousTrack = (byte) Keys.MediaPreviousTrack;
keybd_event(mediaPreviousTrack, mediaPreviousTrack, 0, 0);
keybd_event(mediaPreviousTrack, mediaPreviousTrack, KEYEVENTF_KEYUP, 0);
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment