CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 10 of 10
  1. #1
    Join Date
    Apr 2018
    Posts
    5

    Lightbulb How to insert data into class data que using Custom Mouse Driver ?

    As a little personal project, I am trying to move the mouse without using the MOUSE_EVENT function.

    I have installed a custom mouse driver (moufiltr) and am trying to use the MouseClassServiceCallback routine.

    Code:
    VOID MouseClassServiceCallback(
      _In_    PDEVICE_OBJECT    DeviceObject,
      _In_    PMOUSE_INPUT_DATA InputDataStart,
      _In_    PMOUSE_INPUT_DATA InputDataEnd,
      _Inout_ PULONG            InputDataConsumed
    );
    Would it be possible to use MOUSE_INPUT_DATA to move the mouse ?

    I am looking for some examples to learn from, but I have been unsuccessful.

    This currently works perfectly :
    Code:
    void Mouse::click(int ms)
    {
    	mouse_event(MOUSEEVENTF_RIGHTDOWN, int(X), y, 0, 0);
    	Sleep(ms);
    	mouse_event(MOUSEEVENTF_RIGHTUP, int(X), y, 0, 0);
    }
    but I would like to avoid using the MOUSE_EVENT function to achieve the same result.

  2. #2
    VictorN's Avatar
    VictorN is offline Super Moderator Power Poster
    Join Date
    Jan 2003
    Location
    Hanover Germany
    Posts
    20,396

    Re: How to insert data into class data que using Custom Mouse Driver ?

    Quote Originally Posted by TheOne1337 View Post
    This currently works perfectly :
    Code:
    void Mouse::click(int ms)
    {
    	mouse_event(MOUSEEVENTF_RIGHTDOWN, int(X), y, 0, 0);
    	Sleep(ms);
    	mouse_event(MOUSEEVENTF_RIGHTUP, int(X), y, 0, 0);
    }
    What did you want to achieve with this code and what do you mean by "works perfectly"?

    Quote Originally Posted by TheOne1337 View Post
    but I would like to avoid using the MOUSE_EVENT function to achieve the same result.
    Why "to avoid using the MOUSE_EVENT function"? what is wrong with it?
    Victor Nijegorodov

  3. #3
    Arjay's Avatar
    Arjay is offline Moderator / EX MS MVP Power Poster
    Join Date
    Aug 2004
    Posts
    13,490

    Re: How to insert data into class data que using Custom Mouse Driver ?

    The correct way to do mouse and keyboard input is to use the SendInput api. https://msdn.microsoft.com/en-us/lib...(v=vs.85).aspx

  4. #4
    Join Date
    Apr 2018
    Posts
    5

    Re: How to insert data into class data que using Custom Mouse Driver ?

    Quote Originally Posted by VictorN View Post
    What did you want to achieve with this code and what do you mean by "works perfectly"?
    Maybe some back ground info about my program will help with the big picture.
    I have designed a small "macro" program that helps me to find and right click on a series of drop down menus to "shortcut" myself to an end menu with a single hotkey press.
    Eg. when I press "F1" it will search and find Option 2 from menu 1, then option 1 from menu 2, then option 12 from menu 3.
    To achieve this, I currently find the image, and have my program move the mouse to the desired X & Y co-ordinates with the MOUSE_EVENT code snippet I attached above.

    Quote Originally Posted by Arjay View Post
    The correct way to do mouse and keyboard input is to use the SendInput api.
    Arjay is right about the correct way to move the mouse being SendInput. (also the easiest and simplest)

    Quote Originally Posted by VictorN View Post
    Why "to avoid using the MOUSE_EVENT function"? what is wrong with it?
    Both Mouse_Event and SendInput leave Injected flags which I am trying to avoid.

    I have decided to try and learn how to move the mouse using a mouse filter driver.
    I am currently stuck on this part.

    Code:
    typedef struct _MOUSE_INPUT_DATA {
      USHORT UnitId;
      USHORT Flags;
      union {
        ULONG  Buttons;
        struct {
          USHORT ButtonFlags;
          USHORT ButtonData;
        };
      };
      ULONG  RawButtons;
      LONG   LastX;
      LONG   LastY;
      ULONG  ExtraInformation;
    } MOUSE_INPUT_DATA, *PMOUSE_INPUT_DATA;
    Any help will be apreciated.
    I am desperately searching for a sample program that uses such a method to move the mouse.

    I know there are easier / simpler ways of doing this.

    Regards.

  5. #5
    VictorN's Avatar
    VictorN is offline Super Moderator Power Poster
    Join Date
    Jan 2003
    Location
    Hanover Germany
    Posts
    20,396

    Re: How to insert data into class data que using Custom Mouse Driver ?

    Quote Originally Posted by TheOne1337 View Post
    I am currently stuck on this part.

    Code:
    typedef struct _MOUSE_INPUT_DATA {
      USHORT UnitId;
      USHORT Flags;
      union {
        ULONG  Buttons;
        struct {
          USHORT ButtonFlags;
          USHORT ButtonData;
        };
      };
      ULONG  RawButtons;
      LONG   LastX;
      LONG   LastY;
      ULONG  ExtraInformation;
    } MOUSE_INPUT_DATA, *PMOUSE_INPUT_DATA;
    you should read the docs related to this struct and MouseClassServiceCallback routine.
    Victor Nijegorodov

  6. #6
    Join Date
    Apr 2018
    Posts
    5

    Re: How to insert data into class data que using Custom Mouse Driver ?

    Quote Originally Posted by VictorN View Post
    you should read the docs related to this struct and MouseClassServiceCallback routine.
    I have tried. I am fairly new to programing and am limited to no GUI macros atm.

    I cann't understand both of them. If i had an example of it in use, i think it would help me to wrap my head around the concept.

    any tips will be greatly appreciated.

  7. #7
    VictorN's Avatar
    VictorN is offline Super Moderator Power Poster
    Join Date
    Jan 2003
    Location
    Hanover Germany
    Posts
    20,396

    Re: How to insert data into class data que using Custom Mouse Driver ?

    Quote Originally Posted by TheOne1337 View Post
    ... SendInput leave Injected flags which I am trying to avoid.
    What flag do you mean and why are you trying to avoid them?
    Victor Nijegorodov

  8. #8
    Join Date
    Apr 2018
    Posts
    5

    Re: How to insert data into class data que using Custom Mouse Driver ?

    Quote Originally Posted by VictorN View Post
    What flag do you mean and why are you trying to avoid them?
    MSLLHOOKSTRUCT

    these flags. I am trying to avoid them to simulate human input as closely as possible.

    can you write a small example using MOUSE_INPUT_DATA for me to study ?

  9. #9
    2kaud's Avatar
    2kaud is offline Super Moderator Power Poster
    Join Date
    Dec 2012
    Location
    England
    Posts
    7,822

    Re: How to insert data into class data que using Custom Mouse Driver ?

    MOUSE_INPUT_DATA structure and MouseClassServiceCallback are used by driver routines - not user-level programs.

    [Thread moved to Driver Development]
    All advice is offered in good faith only. All my code is tested (unless stated explicitly otherwise) with the latest version of Microsoft Visual Studio (using the supported features of the latest standard) and is offered as examples only - not as production quality. I cannot offer advice regarding any other c/c++ compiler/IDE or incompatibilities with VS. You are ultimately responsible for the effects of your programs and the integrity of the machines they run on. Anything I post, code snippets, advice, etc is licensed as Public Domain https://creativecommons.org/publicdomain/zero/1.0/ and can be used without reference or acknowledgement. Also note that I only provide advice and guidance via the forums - and not via private messages!

    C++23 Compiler: Microsoft VS2022 (17.6.5)

  10. #10
    Join Date
    Apr 2018
    Posts
    5

    Re: How to insert data into class data que using Custom Mouse Driver ?

    Quote Originally Posted by 2kaud View Post
    MOUSE_INPUT_DATA structure and MouseClassServiceCallback are used by driver routines - not user-level programs.
    [Thread moved to Driver Development]

    correct me if i am wrong, but user level programs can use MOUSE_INPUT_DATA structure and MouseClassServiceCallback to delete, transform, or insert data via the filter service callback.

    Attachment 35213

    But the filter driver itself, is not user-level
    Last edited by TheOne1337; April 17th, 2018 at 02:33 PM. Reason: Quote added

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured