我想知道如何制作一个控制台应用程序来检测用户是否用鼠标滚轮滚动(屏幕上的任何地方)。
我希望它成为控制台应用程序的原因是我可以在后台运行它。我已经搜索了很多东西,但似乎找不到我需要的东西。
最佳答案
您可以阅读以下主题:
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/