gpt4 book ai didi

c# - 在控制台应用程序中检测系统范围的滚动

转载 作者:行者123 更新时间:2023-11-30 17:55:04 24 4
gpt4 key购买 nike

我想知道如何制作一个控制台应用程序来检测用户是否使用鼠标滚轮滚动(屏幕上的任何位置)。

我希望它成为控制台应用程序的原因是我可以在后台运行它。我现在已经搜索了很多,但似乎找不到我需要的东西。

最佳答案

你可以阅读这个主题:

Mouse Wheel Event (C#)

如果您有自己的控件,则可以通过设计器或动态代码轻松地设置此类内容。但是,鼠标需要位于您的控件之上,这样您才能接收到该事件。因此,在您的情况下,您需要在消息过滤器上注册。小心,不要在那里做太多事情。如果你在这个地方做太多,这可能会减慢你的整个应用程序:

public bool PreFilterMessage(ref Message m) 

您也可以在不显示窗体的情况下设置 Windows 窗体项目。这是一个 windows 窗体项目的 program.cs 代码:

static class Program
{
/// <summary>
/// The main entry point for the application.
/// </summary>
[STAThread]
static void Main()
{
Application.EnableVisualStyles();
Application.SetCompatibleTextRenderingDefault(false);
Application.Run(new WindowlessApplicationContext());

}
}

/// <summary>
/// The window less application context.
/// </summary>
internal class WindowlessApplicationContext : ApplicationContext
{
/// <summary>
/// Standard constructor.
/// </summary>
public WindowlessApplicationContext()
{
try
{
//Your code

}
// you mayy add catch here
finally
{
//Close process
Environment.Exit(0);
}
}
}

关于c# - 在控制台应用程序中检测系统范围的滚动,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15380252/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com