Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C / C++ / MFC
  4. [C++] How to change the mouse position in Mouse Hook

[C++] How to change the mouse position in Mouse Hook

Scheduled Pinned Locked Moved C / C++ / MFC
questionc++tutorial
9 Posts 3 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • R Offline
    R Offline
    Rex Miao
    wrote on last edited by
    #1

    Dear All, This is my first time to ask question on this platform. The question is: I want to write a program, which can modify the mouse position to achieve inverting mouse movement, like wanna move up but it goes down. wanna move left but it goes right. here is the callback sample code, but I can get what I want. What can I do?

    LRESULT CALLBACK MouseHookProc2(int nCode, WPARAM wParam, LPARAM lParam)
    {

    if(wParam == WM\_MOUSEMOVE ||wParam == WM\_NCMOUSEMOVE)
    {
    
    	MOUSEHOOKSTRUCT\* data=(MOUSEHOOKSTRUCT\*) lParam;
    	LPARAM lParam2= MAKELPARAM(0,data->pt.y);
    	return CallNextHookEx(NULL,nCode,wParam,lParam2);
    
    }
    

    return CallNextHookEx(NULL,nCode,wParam,lParam);
    }

    P S 2 Replies Last reply
    0
    • R Rex Miao

      Dear All, This is my first time to ask question on this platform. The question is: I want to write a program, which can modify the mouse position to achieve inverting mouse movement, like wanna move up but it goes down. wanna move left but it goes right. here is the callback sample code, but I can get what I want. What can I do?

      LRESULT CALLBACK MouseHookProc2(int nCode, WPARAM wParam, LPARAM lParam)
      {

      if(wParam == WM\_MOUSEMOVE ||wParam == WM\_NCMOUSEMOVE)
      {
      
      	MOUSEHOOKSTRUCT\* data=(MOUSEHOOKSTRUCT\*) lParam;
      	LPARAM lParam2= MAKELPARAM(0,data->pt.y);
      	return CallNextHookEx(NULL,nCode,wParam,lParam2);
      
      }
      

      return CallNextHookEx(NULL,nCode,wParam,lParam);
      }

      P Offline
      P Offline
      pasztorpisti
      wrote on last edited by
      #2

      I think you are approaching the problem from a wrong direction. The mouse works the following way: The hardware sends movement deltas to the machine and to the OS via the driver and there it gets accumulated into a mouse position value. If you want to invert the movement you have to invert the deltas because you simply can't do that with the position. Maybe if you knew the previous value of the position... But even in that case that would be quite a messy solution. Another problem with this solution is that as far as I know most hook types are not allowed to modify the incoming parameters and they have to pass on them to the next hook handler unmodified. You should probably write a mouse filter driver: http://code.msdn.microsoft.com/windowshardware/Moufiltr-WDF-Version-fb57f5de[^] http://www.maf-soft.de/mafmouse/[^]

      R 1 Reply Last reply
      0
      • P pasztorpisti

        I think you are approaching the problem from a wrong direction. The mouse works the following way: The hardware sends movement deltas to the machine and to the OS via the driver and there it gets accumulated into a mouse position value. If you want to invert the movement you have to invert the deltas because you simply can't do that with the position. Maybe if you knew the previous value of the position... But even in that case that would be quite a messy solution. Another problem with this solution is that as far as I know most hook types are not allowed to modify the incoming parameters and they have to pass on them to the next hook handler unmodified. You should probably write a mouse filter driver: http://code.msdn.microsoft.com/windowshardware/Moufiltr-WDF-Version-fb57f5de[^] http://www.maf-soft.de/mafmouse/[^]

        R Offline
        R Offline
        Rex Miao
        wrote on last edited by
        #3

        Thanks for your information lead me to the right direction. I will study driver filter then. thanks

        P 1 Reply Last reply
        0
        • R Rex Miao

          Thanks for your information lead me to the right direction. I will study driver filter then. thanks

          P Offline
          P Offline
          pasztorpisti
          wrote on last edited by
          #4

          You are welcome! Good luck, have fun!

          R 1 Reply Last reply
          0
          • R Rex Miao

            Dear All, This is my first time to ask question on this platform. The question is: I want to write a program, which can modify the mouse position to achieve inverting mouse movement, like wanna move up but it goes down. wanna move left but it goes right. here is the callback sample code, but I can get what I want. What can I do?

            LRESULT CALLBACK MouseHookProc2(int nCode, WPARAM wParam, LPARAM lParam)
            {

            if(wParam == WM\_MOUSEMOVE ||wParam == WM\_NCMOUSEMOVE)
            {
            
            	MOUSEHOOKSTRUCT\* data=(MOUSEHOOKSTRUCT\*) lParam;
            	LPARAM lParam2= MAKELPARAM(0,data->pt.y);
            	return CallNextHookEx(NULL,nCode,wParam,lParam2);
            
            }
            

            return CallNextHookEx(NULL,nCode,wParam,lParam);
            }

            S Offline
            S Offline
            Stephen Hewitt
            wrote on last edited by
            #5

            Give calling SetCursorPos[/\] a try.

            Steve

            R 1 Reply Last reply
            0
            • S Stephen Hewitt

              Give calling SetCursorPos[/\] a try.

              Steve

              R Offline
              R Offline
              Rex Miao
              wrote on last edited by
              #6

              try it alreay. but it can't fullfill the use I need. even if it didn't have any effect at all. guess the mouse move event reflash is too quick.

              1 Reply Last reply
              0
              • P pasztorpisti

                You are welcome! Good luck, have fun!

                R Offline
                R Offline
                Rex Miao
                wrote on last edited by
                #7

                Dear Bro, Do you know "sakasamouse"? That tool can do excatly what I want. And it seems it is not a driver. because it is an .exe file and has an .dll with it. Do you know how it do? Thanks in advance

                P 1 Reply Last reply
                0
                • R Rex Miao

                  Dear Bro, Do you know "sakasamouse"? That tool can do excatly what I want. And it seems it is not a driver. because it is an .exe file and has an .dll with it. Do you know how it do? Thanks in advance

                  P Offline
                  P Offline
                  pasztorpisti
                  wrote on last edited by
                  #8

                  No, I don't know it. I use my mouse as it comes with my windows.

                  R 1 Reply Last reply
                  0
                  • P pasztorpisti

                    No, I don't know it. I use my mouse as it comes with my windows.

                    R Offline
                    R Offline
                    Rex Miao
                    wrote on last edited by
                    #9

                    OKay. thanks anyway. Maybe I should ask again...

                    1 Reply Last reply
                    0
                    Reply
                    • Reply as topic
                    Log in to reply
                    • Oldest to Newest
                    • Newest to Oldest
                    • Most Votes


                    • Login

                    • Don't have an account? Register

                    • Login or register to search.
                    • First post
                      Last post
                    0
                    • Categories
                    • Recent
                    • Tags
                    • Popular
                    • World
                    • Users
                    • Groups