How to detect the mouse wheel?

Asked

Viewed 108 times

4

I need to detect if the user is scrolling down the mouse scroll.

I tried with the GetKeyState, but it seems that there is no way to pass as parameter the scrolling of the mouse scroll.

I also found that, but I couldn’t figure out how to use it in C#.

Code:

if (/* Aqui eu devo checar se o usuário está rolando o scroll */)
{
    Stopwatch s = new Stopwatch();
    s.Start();
    while (s.Elapsed < TimeSpan.FromMilliseconds(300))
    {
        //Irrelevante
    }
    s.Stop();
}

I also found that, but I have no idea how to use in a console application.

  • What is the purpose ? windows Forms ?

  • Console app.

  • I don’t know if you have this console feature.

  • see if it helps: https://stackoverflow.com/questions/9302891/get-wheel-delta-wparam-macro-in-c-sharp

  • @Rovannlinhalis I had come to this question already before making my own. I didn’t understand anything that goes on there kkk

  • If you tell me what purpose you need, it might be easier to help

  • @Rovannlinhalis Ué, I need to detect if the user is scrolling down to execute a code.

Show 2 more comments

1 answer

1


There are some ways.

  1. Call Readconsoleinput you will receive a MOUSE_WHEELED if the mouse Whell is rotated.
  2. Create a Windows.Form program without the windows.form environment so you’ll have mouse properties in a console environment! [That would be my choice]

ex windows.Form without the form, only the console.

static class Program
{
    [STAThread]
    static void Main()
    {
        Application.EnableVisualStyles();
        Application.SetCompatibleTextRenderingDefault(false);
        Application.Run(new WindowlessApplicationContext());

    }
}


internal class WindowlessApplicationContext : ApplicationContext
{
    public WindowlessApplicationContext()
    {
        try
        {
            //Your code

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

More information:

https://stackoverflow.com/questions/15856386/capturing-mouse-wheel-events-in-console-application

http://www.pinvoke.net/default.aspx/kernel32/ReadConsoleInput.html

  • The problem with doing with Forms, is that I’m injecting the code in another process, in this I think it wouldn’t even work with an overlay. Could you give me an example in the first way?

  • good. I still think that windows.form without the form is the best solution, alias in some tests that had done it had a superior performance to the console!. I will edit my reply to try to include as much information as the first method

Browser other questions tagged

You are not signed in. Login or sign up in order to post.