Thread: Controlling Mouse movement?

  1. #1
    Registered User
    Join Date
    Jul 2004
    Posts
    8

    Controlling Mouse movement?

    I have no idea where to ask this (on the internet) so please bear with me. I am looking for a program that will stop the mouse from moving along one axis. An example of this is in a paint program if you hold shift down it will draw a straight line in one direction. I am looking for this effect but with the mouse, not letting it move outside of one axis regardless of user control (moving diagonal will keep it just in the one selected plane). Preferably with a toggle button to turn on/off. I have downloaded some software from download.com but none of them have this feature. I even took an old mouse and broke one of the rollers but the ball doesn't move as freely without the roller and it's hard to control the speed. If anyone knows of any program please share.

    P.S.: I am also a programmer although I would consider myself a novice windows one (mostly did console stuff). If there are any good articles/tutorials on this subject you can post them here too. Thanks.

  2. #2
    Yes, my avatar is stolen anonytmouse's Avatar
    Join Date
    Dec 2002
    Posts
    2,544
    Is this for your own program, or to target another program? For example, do you wnat to be able to press Ctrl-Alt-H and have the cursor locked on the horizontal plain in Photshop?

    This is reasonably straight forward to do with ClipCursor(). However, if you need to do it in a target process, it may involve remote code injection to run ClipCursor from the right application.

    Code:
    // Sample only
    #include <windows.h>
    #include <stdio.h>
    
    int main(void)
    {
    	POINT pt;
    
    	GetCursorPos(&pt);
    
    	RECT rc = { pt.x, 0, pt.x + 1,  1024 };
    
    	ClipCursor(&rc);
    
    	getchar();
    	ClipCursor(NULL);
    	return 0;
    }

  3. #3
    Registered User
    Join Date
    Jul 2004
    Posts
    8
    I want to limit the mouse movement to one axis in programs that I did not write or have the source code to. I'm looking for something easy, where maybe it won't detect one axis of movement (something similar to turning it off in control panel, if that was available would be great). Appreciate your help.

  4. #4
    Registered User
    Join Date
    Jul 2004
    Posts
    8
    I was wondering if there may be some built in Windows function to stop all mouse movement on a certain axis? I am not aware of anything though. I use a logitech mx700 optical mouse if anyone cares.

  5. #5
    i dont know Vicious's Avatar
    Join Date
    May 2002
    Posts
    1,200
    hmmm... seems interesting...

    I am almost positive there is a way.

    My lack of skills keeps me from writing a program like this but I am sure someone could.

    What would need to happen is to make a program that runs in the background or rests in the system tray and constantly scan the keyboard and restrict certain mouse movements depending on what keys are pressed.

    I ve seen programs run in the tray and mimic keyboard controls through a usb device so there is surely a way to accomplish what your seeking to do

    EDIT: If you can make any sense out of that post.... Wow....

  6. #6
    Registered User
    Join Date
    Jul 2004
    Posts
    8
    UPDATE: I actually found a program yesterday that restricted the cursor movement to just one axis, which is what I was asking for before and what I thought I wanted. Alas, it's still not quite what I want as I need the actual mouse movement to be restricted. I suppose in that particular program windows is still sensing mouse movement, it's only moving the cursor in one direction.

    I have a feeling the problem may be a LOT deeper than I originally thought. I may need to modify a mouse driver or something. If anyone has any input please leave a message.

    EDIT: I have tried programs where the mouse is controlled by say a keyboard, but those don't work either. It may be because of the way the programs I want it to work on are written or because the cursor is not freely available on the screen when I run the programs I need that option on. The best example I can think of if your still confused is: Picture you have a program that you use to view a 3d object now you just use only your mouse to rotate that object. I'm looking to just rotate about the x plane perfectly, without moving in the y direction.
    Last edited by raum; 07-02-2004 at 05:18 AM.

  7. #7
    mustang benny bennyandthejets's Avatar
    Join Date
    Jul 2002
    Posts
    1,401
    I'm not sure about the specifics, but the steps you will need to take involve the following:

    1. Write a DLL which, upon attachment to a process, adds the accelerator you desire to the program. This DLL also contains the code to handle the accelerator, where you will use ClipCursor() to toggle on and off the mono-axis movement.

    2. Edit the registry so that your DLL is loaded into every program that is run. This is simple, but I can't remember off the top of my head where to put the registry entry.

    What I am unsure about is how the DLL would add the accelerator. When the DLL is attached to the process, there won't be any accelerator tables loaded into memory. I'm sure there is a way around this though. Someone else will have to fill in the details.

    I'm pretty sure this is the best way to go about it.
    [email protected]
    Microsoft Visual Studio .NET 2003 Enterprise Architect
    Windows XP Pro

    Code Tags
    Programming FAQ
    Tutorials

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Simulating mouse movement in other windows
    By Wiretron in forum Windows Programming
    Replies: 11
    Last Post: 10-13-2007, 08:11 AM
  2. simple mouse movement program
    By skankles in forum Windows Programming
    Replies: 3
    Last Post: 05-27-2007, 07:54 PM
  3. Recognizing mouse movement???
    By jrkid in forum C++ Programming
    Replies: 3
    Last Post: 07-19-2004, 11:49 AM
  4. Mouse Movement
    By Extol in forum Windows Programming
    Replies: 6
    Last Post: 04-22-2003, 08:48 PM
  5. Need to read mouse movement in program
    By Unregistered in forum C++ Programming
    Replies: 4
    Last Post: 01-03-2002, 03:15 PM