如何在c#中的鼠标点击和键盘按事件事件事件中执行某些操作 [英] how to perform some actions in mouse click and keyboard press events event event in c#
本文介绍了如何在c#中的鼠标点击和键盘按事件事件事件中执行某些操作的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在尝试创建一个exe,当我运行exe时,它应该对每个鼠标点击和键盘按下事件执行一些操作,而不会触发任何其他按钮点击事件。
私有 void btn_Click( object sender,EventArgs e)
{
if (e.Button == System.Windows.Forms.MouseButtons.Right){MessageBox.Show( 右键单击);}
if (e.Button == System.Windows.Forms.MouseButtons.Left){MessageBox.Show( 左键单击);}
}
我用谷歌搜索它,但我找不到我的要求。任何人都可以帮助我。
提前谢谢
解决方案
我想你会找到一个解决方案在此CodeProject文章中:
处理C#中的全局鼠标和键盘挂钩 [ ^ ]
最新的项目可以在GitHub上找到:
gmamaladze / globalmousekeyhook - C# - GitHub [ ^ ]
我瞥了一眼它看起来非常简单直接。
I am trying to create an exe, when i run the exe it should perform some action on each mouse click and keyboard press events without triggering any other button click events.
private void btn_Click(object sender, EventArgs e)
{
if (e.Button == System.Windows.Forms.MouseButtons.Right){MessageBox.Show("Right click");}
if (e.Button == System.Windows.Forms.MouseButtons.Left){MessageBox.Show("Left click");}
}
I googled it and i don't find my requirement. can anybody please help me.
Thanks in advance
解决方案
I think you'll find a solution in this CodeProject article:
Processing Global Mouse and Keyboard Hooks in C#[^]
It's most up-to-date project can be found on GitHub:
gmamaladze/globalmousekeyhook - C# - GitHub[^]
I took a glance at it and it looks really easy and straight forward.
这篇关于如何在c#中的鼠标点击和键盘按事件事件事件中执行某些操作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文