3

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.

default
  • 11,485
  • 9
  • 66
  • 102
M. Boeckx
  • 252
  • 1
  • 5
  • 18
  • 3
    This is not a _real question_. What have you tried? Show your effort here. Please read [FAQ] and [ask] – Soner Gönül Mar 13 '13 at 08:31
  • I can't seem to get started, I've tried searching for some pieces of code but they all seem to be bound to the window or only working in a form application. – M. Boeckx Mar 13 '13 at 08:34
  • A Console Application runs in a console, not in the background. Maybe you want a Windows Service. But "detecting mousewheel" is dangerously close to keylogging... – Corak Mar 13 '13 at 08:41

2 Answers2

1

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);
        }
    }
}
Community
  • 1
  • 1
Patrick
  • 907
  • 9
  • 22
  • Thank you very much! :) The hidden Windows form is a nice extra! I think this is what I need. – M. Boeckx Mar 13 '13 at 08:44
  • Hello, you are welcome. You may check the link I have provided. It should be very easy to implement. If the user scroll, you may call something from here: if (m.Msg == 0x20a) – Patrick Mar 13 '13 at 09:12
0

One way to achieve it is using Raw Input via P/Invoke. Start here:

http://msdn.microsoft.com/en-us/library/ms645543(v=vs.85).aspx,
http://msdn.microsoft.com/en-us/library/ms645536(v=vs.85).aspx.

Referred from: http://www.codeproject.com/Questions/217948/I-need-to-capture-mouse-events-in-Console

Civa
  • 2,058
  • 2
  • 18
  • 30