How to detect the mouse wheel?

4

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

I tried with GetKeyState , but it seems that there is no way to scroll the mouse scroll.

I also found this , but not I could understand 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 this , but I have no idea how to use it in a console application.

    
asked by anonymous 29.07.2017 / 21:47

1 answer

1

There are a few ways.

  • Call ReadConsoleInput you will get MOUSE_WHEELED if the mouse whell is rotated
  • Create a Windows.Form program without the windows.form environment so you will have the mouse properties in a console environment! [This would be my choice]
  • ex from windows.Form without the form, just 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:

    link

    link

        
    22.08.2017 / 18:26