Solved

How do I disable or slow down the mouse?

Posted on 1998-10-02
9
398 Views
Last Modified: 2012-06-21
Is there a method available to disable the mouse or slow the mouse speed down to a very slow movement. My platform is Windows NT 4.0 and I use C++.
0
Comment
Question by:Finch
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 4
  • 2
  • 2
  • +1
9 Comments
 
LVL 6

Expert Comment

by:thresher_shark
ID: 1174295
Here's a possibility:

1) Set a timer for say 25ms.
2) Get the mouse position with GetCurPos.
3) Store the values in some variables.
4) In the next call to the timer function, get the cursor points again.
5) Calculate the change in x and y values.
6) Divide the change by some number (the larger the number, the slower the mouse will move).
7) Set the new position to the old position plus the change in coordinates divided by the magic number.

Now, I am no professional, my logic is probably flawed somewhere along the line... perhaps I will test it and let you know what happens.
0
 
LVL 6

Expert Comment

by:thresher_shark
ID: 1174296
Forgot to add that the function that you use to set the new coordinates is SetCurPos.
0
 
LVL 3

Expert Comment

by:daitt
ID: 1174297
To get two mouse threshold values and the mouse speed, call:
SystemParametersInfo(SPI_GETMOUSE,0,&buf,0);
with buf is an array of 3 integers to store these values.
Then change the value of buf, and call:
SystemParametersInfo(SPI_SETMOUSE,0,&buf,0);

These function is in USER32.LIB (#include winuser.h)
0
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 3

Expert Comment

by:daitt
ID: 1174298
I'm sorry, if you declare:
int buf[3];
then you have to call:

SystemParametersInfo(SPI_GETMOUSE,0,buf,0);
//not    &buf

0
 

Author Comment

by:Finch
ID: 1174299
This is a very good answer, but I've tried it already with disappointing results.  The cursor did seem to slow down but the best I could get was about a 50% reduction in cursor speed. I tried values from 0 to 300 in the 3rd element (i.e. buf[2] = 0).
Do you know of any way to totally freeze, hide or disable the cursor?
0
 
LVL 86

Accepted Solution

by:
jkr earned 50 total points
ID: 1174300
Well, the only way to totally 'control' any mouse related events is to use a system wide message hook (see 'SetWindowsHookEx()' and 'WH_GETMESSAGE', the hook has to reside in a DLL), e.g.:

LRESULT CALLBACK HookProc   (   int     nCode,  // hook code
                                WPARAM  wParam, // removal flag
                                LPARAM  lParam  // address of structure with message
                            )
{
    PMSG    pmsg    =   ( PMSG) lParam;
    MSG     msg;

    if  (   0   >   nCode   ||  PM_NOREMOVE ==  wParam)
        {
            return  (   CallNextHookEx  (   g_hhk,
                                            nCode,
                                            wParam,
                                            lParam
                                        )
                    );
        }

    if  (   /* ... check whether it's a mouse message */
            PeekMessage (   &msg,
                            pmsg->hwnd,
                            WM_MOUSEFIRST,
                            WM_MOUSELAST,
                            PM_NOREMOVE
                        )
        )
        {
            /* appropriate action, e.g. suppress msg by removing it /*
            PeekMessage (   &msg,
                            pmsg->hwnd,
                            WM_MOUSEFIRST,
                            WM_MOUSELAST,
                            PM_REMOVE
                        );
        }

.
}

0
 
LVL 6

Expert Comment

by:thresher_shark
ID: 1174301
If all you want to do is freeze the mouse, I know of a much simpler way.

Use:
RECT rect;
POINT point;

GetCursorPos (&point);

rect.top = point.y;
rect.left = point.x;
rect.bottom = point.y;
rect.right = point.x;

ClipCursor (rect);

I think that ought to do it.
0
 
LVL 6

Expert Comment

by:thresher_shark
ID: 1174302
Then, to allow the cursor to resume moving, do the same thing only in the RECT structure, fill in the screen resolution, i.e. 0, 0, 640, 480.
0
 

Author Comment

by:Finch
ID: 1174303
JKR's answer looks like it will work for my situation, THANKS.
0

Featured Post

Enroll in May's Course of the Month

May’s Course of the Month is now available! Experts Exchange’s Premium Members and Team Accounts have access to a complimentary course each month as part of their membership—an extra way to increase training and boost professional development.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

In days of old, returning something by value from a function in C++ was necessarily avoided because it would, invariably, involve one or even two copies of the object being created and potentially costly calls to a copy-constructor and destructor. A…
Introduction This article is a continuation of the C/C++ Visual Studio Express debugger series. Part 1 provided a quick start guide in using the debugger. Part 2 focused on additional topics in breakpoints. As your assignments become a little more …
The goal of the tutorial is to teach the user how to use functions in C++. The video will cover how to define functions, how to call functions and how to create functions prototypes. Microsoft Visual C++ 2010 Express will be used as a text editor an…
The goal of the video will be to teach the user the difference and consequence of passing data by value vs passing data by reference in C++. An example of passing data by value as well as an example of passing data by reference will be be given. Bot…

734 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question