VirtualKeyCode.MEDIA_PLAY_PAUSE不工作 [英] VirtualKeyCode.MEDIA_PLAY_PAUSE not working

查看:776
本文介绍了VirtualKeyCode.MEDIA_PLAY_PAUSE不工作的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我希望你们能帮助我。我已经写在我做的本质上是监听来自Android设备的HTTP调用服务器C#一个小的Windows应用程序。应用基本上充当远程 - 如果它听到静音,它将静音计算机的体积,等等。我的问题是,我有一些问题暂停前台应用程序。我特别想模仿播放/暂停按钮,您就这么多键盘,这些天看到的。我这样做的方法是使用Windows输入模拟器项目( http://inputsimulator.codeplex.com/)来模拟播放/暂停键。不幸的是,我没有收到任何类型的明显反应 - 没有什么特别的事情正在发生。由于担心我的设置,我切换VirtualKeyCode.MEDIA_PLAY_PAUSE标志静音键的标志,并成功静音我的机器。请注意,我使用Windows Media Player,因此我有信心它监听呼叫。

I'm hoping you guys can help me out. I have a small windows application written in C# that I'm making that is essentially a server listening for HTTP calls from an android device. The application basically acts as a remote - if it hears mute, it will mute the volume of the computer, and so on. My issue is I'm having some problems with pausing the foreground application. I'm specifically trying to imitate the play/pause button you see on so many keyboards these days. My method for doing so has been to use the Windows Input Simulator project (http://inputsimulator.codeplex.com/) to simulate that play/pause key. Unfortunately, I'm not getting any type of discernible response - nothing in particular is happening. Fearing my set up, I switched the VirtualKeyCode.MEDIA_PLAY_PAUSE flag to the mute key flag and successfully muted my machine. Note that I am using Windows Media Player so I'm confident it's listening for the call.

我想知道的,是没有任何额外的设置,我需要做的之前,我可以暂停任何当前正在播放媒体?是否有任何其他的方式来实现我后,而不是模拟按键?任何帮助将非常感谢你们!

What I'm wondering is, is there any extra setup I need to do before I can pause whatever media is currently playing? Are there any other ways to achieve what I'm after rather than simulating the key press? Any help would be much appreciated guys!

推荐答案

要模拟紧迫的媒体播放的/暂停按钮,你需要通过WM_APPCOMMAND消息与SendMessage函数。

To emulate the pressing of the Media Play / Pause button you need to pass WM_APPCOMMAND messages with SendMessage.

[DllImport("user32.dll")]
extern IntPtr SendMessageW(IntPtr hWnd, int Msg, IntPtr wParam, IntPtr lParam);
int WM_APPCOMMAND = 0x0319;



然后,当你想模拟按下暂停按钮。

Then when you want to simulate the pressing of the pause button.

void AppCommand(AppComandCode commandCode)
{
    var windowInteropHelper = new WindowInteropHelper(this);

    int CommandID = (int)commandCode << 16;
    SendMessageW(windowInteropHelper.Handle, WM_APPCOMMAND, windowInteropHelper.Handle, (IntPtr)CommandID);
}

如果您的应用程序不是一个WPF应用程序,试试这个功能而不是

If your application is not a WPF application, try this function instead

void AppCommand(AppComandCode commandCode)
{
    int CommandID = (int)commandCode << 16;
    SendMessageW(Process.GetCurrentProcess().MainWindowHandle, WM_APPCOMMAND, Process.GetCurrentProcess().MainWindowHandle, (IntPtr)CommandID);
}



在哪里命令代码为以下之一:

Where command code is one of the following:

public enum AppComandCode : uint
{
    BASS_BOOST = 20,
    BASS_DOWN = 19,
    BASS_UP = 21,
    BROWSER_BACKWARD = 1,
    BROWSER_FAVORITES = 6,
    BROWSER_FORWARD = 2,
    BROWSER_HOME = 7,
    BROWSER_REFRESH = 3,
    BROWSER_SEARCH = 5,
    BROWSER_STOP = 4,
    LAUNCH_APP1 = 17,
    LAUNCH_APP2 = 18,
    LAUNCH_MAIL = 15,
    LAUNCH_MEDIA_SELECT = 16,
    MEDIA_NEXTTRACK = 11,
    MEDIA_PLAY_PAUSE = 14,
    MEDIA_PREVIOUSTRACK = 12,
    MEDIA_STOP = 13,
    TREBLE_DOWN = 22,
    TREBLE_UP = 23,
    VOLUME_DOWN = 9,
    VOLUME_MUTE = 8,
    VOLUME_UP = 10,
    MICROPHONE_VOLUME_MUTE = 24,
    MICROPHONE_VOLUME_DOWN = 25,
    MICROPHONE_VOLUME_UP = 26,
    CLOSE = 31,
    COPY = 36,
    CORRECTION_LIST = 45,
    CUT = 37,
    DICTATE_OR_COMMAND_CONTROL_TOGGLE = 43,
    FIND = 28,
    FORWARD_MAIL = 40,
    HELP = 27,
    MEDIA_CHANNEL_DOWN = 52,
    MEDIA_CHANNEL_UP = 51,
    MEDIA_FASTFORWARD = 49,
    MEDIA_PAUSE = 47,
    MEDIA_PLAY = 46,
    MEDIA_RECORD = 48,
    MEDIA_REWIND = 50,
    MIC_ON_OFF_TOGGLE = 44,
    NEW = 29,
    OPEN = 30,
    PASTE = 38,
    PRINT = 33,
    REDO = 35,
    REPLY_TO_MAIL = 39,
    SAVE = 32,
    SEND_MAIL = 41,
    SPELL_CHECK = 42,
    UNDO = 34,
    DELETE = 53,
    DWM_FLIP3D = 54
}

这篇关于VirtualKeyCode.MEDIA_PLAY_PAUSE不工作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆