CSDN下载地址:https://download.csdn.net/download/sns1991sns/88041637
gitee下载地址:https://gitee.com/linsns/snssharp
一、键盘事件,使用SnsKeyboardHook
按键事件共有3个:
KeyDown(按键按下)
KeyUp(按键松开)
KeyPress(按键按下并松开)
以KeyDown事件为例,使用代码如下:
SnsKeyboardHook snsKeyboardhook = new SnsKeyboardHook();
snsKeyboardhook.KeyDown += SnsKeyboardhook_KeyDown;
snsKeyboardhook.Start();
private void SnsKeyboardhook_KeyDown(object sender, KeyEventArgs e)
{
labState.Text = string.Format("状态:当前按下键盘{0}", e.KeyCode);
}
其中SnsKeyboardhook_KeyDown就是按键响应函数。
二、鼠标事件,使用SnsMouseHook
鼠标事件共有6个:
MouseDown(鼠标按下)
MouseUp(鼠标松开)
MouseMove(鼠标移动)
MouseWheel(鼠标滚动鼠轮)
Click(鼠标单击)
DoubleClick(鼠标双击)
以MouseDown事件为例,使用代码如下:
SnsMouseHook snsMouseHook = new SnsMouseHook();
snsMouseHook.MouseDown += SnsMouseHook_MouseDown;
snsMouseHook.Start();
private void SnsMouseHook_MouseDown(object sender, MouseEventArgs e)
{
labState.Text = string.Format("状态:当前按下鼠标{0}", e.Button);
}
其中SnsMouseHook_MouseDown就是鼠标按下响应函数。
三、模拟键盘事件,使用SnsKeyboardSimulator
模拟按键事件共有3个:
KeyDown(按键按下)
KeyUp(按键松开)
KeyPress(按键按下并松开)
模拟按下空格键:SnsKeyboardSimulator.KeyDown(Keys.Space);
模拟按下确定键:SnsKeyboardSimulator.KeyDown(Keys.Enter);
四、模拟鼠标事件,使用SnsMouseSimulator
模拟鼠标事件共有5个:
MouseDown(鼠标按下)
MouseUp(鼠标松开)
MouseMove(鼠标移动)
Click(鼠标单击)
DoubleClick(鼠标双击)
模拟鼠标左键按下:SnsMouseSimulator.MouseDown(MouseButtons.Left);
模拟鼠标移动:SnsMouseSimulator.MouseMouve(x, y);文章来源:https://www.toymoban.com/news/detail-624870.html
效果:
技术交流
QQ群: 577276243文章来源地址https://www.toymoban.com/news/detail-624870.html
到了这里,关于C#使用SnsSharp实现鼠标键盘钩子,实现全局按键响应的文章就介绍完了。如果您还想了解更多内容,请在右上角搜索TOY模板网以前的文章或继续浏览下面的相关文章,希望大家以后多多支持TOY模板网!