Send multimedia commands

后端 未结 3 1940
春和景丽
春和景丽 2021-01-20 17:38

Is there some way that I can send multimedia control commands like next song, pause, play, vol up, etc. to the operating system? Commands that are sent when pressing Fn

3条回答
  •  误落风尘
    2021-01-20 18:12

    You can use keybd_event to simulate keys presses, you have to simulate key down and then key up in order to recognize correctly

        [DllImport("user32.dll", SetLastError = true)]
        public static extern void keybd_event(byte virtualKey, byte scanCode, uint flags, IntPtr extraInfo);
        public const int VK_MEDIA_NEXT_TRACK = 0xB0;
        public const int VK_MEDIA_PLAY_PAUSE = 0xB3;
        public const int VK_MEDIA_PREV_TRACK = 0xB1;
        public const int KEYEVENTF_EXTENDEDKEY = 0x0001; //Key down flag
        public const int KEYEVENTF_KEYUP = 0x0002; //Key up flag
    
        private void ButtonClick(object sender, EventArgs e)
            keybd_event(VK_MEDIA_PREV_TRACK, 0, KEYEVENTF_EXTENDEDKEY, IntPtr.Zero);
            keybd_event(VK_MEDIA_PREV_TRACK, 0, KEYEVENTF_KEYUP, IntPtr.Zero);
        }`
    

提交回复
热议问题