Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Detect system wide scrolling in Console application

I was wondering how I could make a console application that detects if the user scrolls with his mousewheel (anywhere on screen).

The reason that I want it to be a console application would be that I can run it in the background. I've searched quite a bit now and I can't seem to find what I need.

like image 740
M. Boeckx Avatar asked Mar 02 '26 09:03

M. Boeckx


1 Answers

you may read this topic:

Mouse Wheel Event (C#)

If you have own controls, you can setup such things very easily throught the designer, or in code dynamically. However, the mouse needs to be on top of your control, so that you will receive the event. So in your case you need to register on the message filter. Take care, that you do not do to much in there. This may slow down your whole application, if you do to much at this place:

public bool PreFilterMessage(ref Message m) 

You can also setup a windows forms project without showing a form either. Here is a program.cs code of a windows forms project:

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);
        }
    }
}
like image 177
Patrick Avatar answered Mar 03 '26 23:03

Patrick