最小化应用程序时捕获媒体密钥 [英] Capture Media Keys when Application is Minimized

查看:23
本文介绍了最小化应用程序时捕获媒体密钥的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想为我正在开发的媒体播放器提供一个选项,以使媒体键即使在最小化时也能正常工作.在没有焦点的情况下在 C# 中捕获和处理这些关键事件的最佳方法是什么?有没有可能?

I want to provide an option with a media player I'm working on for the media keys to work even when it's minimized. What's the best way to capture and process those key events in C# without having focus? Is it even possible?

推荐答案

我不认为有一个简单的方法可以做到这一点,但 这个(使用窗口消息在 C# 中实现全局系统挂钩) 项目可能会有所帮助.我在下面添加了代码

I don't think that there is an easy way to do this but this (Using Window Messages to Implement Global System Hooks in C#) project may help. I added below code

    _GlobalHooks.Keyboard.KeyboardEvent += (w, l) => 
    {
          this.LblMouse.Text = "KEY: " + w.ToInt32().ToString("X8") + " " + l.ToInt32().ToString("X8");
    };
    _GlobalHooks.Keyboard.Start();

到 GlobalHookTest 的 Form1 的构造函数,并且能够监控所有的键盘事件.

to the constructor of Form1 of GlobalHookTest and was able to monitor all the keyboard events.

这篇关于最小化应用程序时捕获媒体密钥的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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