我知道 c#,我想为非活动和活动鼠标左/右按钮创建一个功能(在 c# 代码中),就像 AHK 程序一样。你能帮助我吗?
问问题
1355 次
1 回答
0
看看https://globalmousekeyhook.codeplex.com/,它拥有完整的全局键盘和鼠标钩子功能。
下面的示例基于提到的用于鼠标右键单击抑制的库
右键单击抑制器
using System;
using System.Windows.Forms;
using MouseKeyboardActivityMonitor.WinApi;
namespace Demo
{
class MouseRightClickDisable:IDisposable
{
private readonly MouseHookListener _mouseHook;
public MouseRightClickDisable()
{
_mouseHook=new MouseHookListener(new GlobalHooker());
_mouseHook.MouseDownExt += MouseDownExt;
_mouseHook.Enabled = true;
}
private void MouseDownExt(object sender, MouseEventExtArgs e)
{
if (e.Button != MouseButtons.Right) { return; }
e.Handled = true; //suppressing right click
}
public void Dispose()
{
_mouseHook.Enabled = false;
_mouseHook.Dispose();
}
}
}
用法
internal static class Program
{
[STAThread]
private static void Main()
{
using (new MouseRightClickDisable())
Application.Run();
}
}
控制台示例
注意:添加System.Windows.Forms.dll
为您的控制台应用程序的参考
internal static class Program
{
[STAThread]
private static void Main()
{
Console.WriteLine("Mouse Hook");
// our UI thread here
var t = new Thread(() =>
{
using (new MouseRightClickDisable())
Application.Run();
});
t.Start();
//some console task here!
for (var i = 0; i < 10; i++)
{
Console.WriteLine("Console Task {0}",i);
Thread.Sleep(100);
}
Console.WriteLine("press any key to terminate the application...");
Console.ReadKey();
Application.Exit();
}
}
于 2014-10-09T18:32:57.153 回答