C#:键盘钩子 [英] C# : Keyboard Hook
问题描述
我不知道问题的更好的头衔,但我心底说明我的问题。
i dont know a better title for the question , but i`ll illustrate my problem.
我工作的应用程序,它就像一个MP3播放器,它使用多媒体键播放/暂停,停止乐曲,其实我做这工作,但FormApplication必须在顶部[聚焦]
I am working on application that acts like a mp3 player , it uses the Multimedia keys to play/pause , stop the song , i actually made it work but the FormApplication must be in the top [Focused]
protected override void WndProc(ref Message msg)
{
if (msg.Msg == 0x319) // WM_APPCOMMAND message
{
// extract cmd from LPARAM (as GET_APPCOMMAND_LPARAM macro does)
int cmd = (int)((uint)msg.LParam >> 16 & ~0xf000);
switch (cmd)
{
case 13: // APPCOMMAND_MEDIA_STOP constant
MessageBox.Show("Stop");
break;
case 14: // APPCOMMAND_MEDIA_PLAY_PAUSE
MessageBox.Show("Play/Pause");
break;
case 11: // APPCOMMAND_MEDIA_NEXTTRACK
MessageBox.Show("Next");
break;
case 12: // APPCOMMAND_MEDIA_PREVIOUSTRACK
MessageBox.Show("Previous");
break;
default:
break;
}
}
base.WndProc(ref msg);
}
private void Form1_KeyPress(object sender, KeyPressEventArgs e)
{
Message m = new Message();
m.Msg = e.KeyChar;
WndProc(ref m);
}
所以我需要做的是:使多媒体键工作,即使该方案的背景,而不是在顶部或专注,就像AOL的Winamp和Windows Media Player是如何工作的。
So what i need to do is : making the multimedia keys work even if the program is on the background and is not on top or focused , just like how winamp and Windows Media Player works.
我在互联网上搜索了很多,但其中大部分给了我类似我使用的一个方法。
I searched a lot on the internet but most of them gives me a way similar to the one i am using.
感谢您很多关于您的帮助提前。
Thank you a lot for your help in advance.
推荐答案
<一个href=\"http://www.$c$cproject.com/Articles/7294/Processing-Global-Mouse-and-Keyboard-Hooks-in-C\">Processing全球鼠标和键盘钩子在C#。
我发现这篇文章非常有用。
I found that article quite useful.
这篇关于C#:键盘钩子的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!