我需要知道如何检测控制台应用程序中的鼠标单击(而不是赢得表格!)。我现在尝试执行的方式无效。
static void Main ( string [ ] args ) {
while(true){
if (Mouse.LeftButton == MouseButtonState.Pressed){
Console.WriteLine("Left mouse button was pressed");
}
}
}
如果您可以使用nuGet软件包,请安装以下软件包:https://www.nuget.org/packages/MouseKeyHook/5.6.0?_src=template并浏览/修改示例或如下:
using System;
using System.Threading;
using Gma.System.MouseKeyHook;
namespace ConsoleHook
{
internal class LogMouse
{
public static void Do(Action quit)
{
Console.WriteLine("Press Q to quit.");
Hook.GlobalEvents().MouseDown += (sender, e) =>
{
Console.Write(e.Button);
};
Hook.GlobalEvents().KeyPress += (sender, e) =>
{
//Console.Write(e.KeyChar);
if (e.KeyChar == 'q') quit();
};
}
}
}
ps。它可以在控制台应用程序中使用。pps。您可以对其进行自定义以检测鼠标左/右键。