Boldijar Paul
Boldijar Paul

Reputation: 5495

C# freeze ONLY mouse movement

I am trying to disable just the mouse movement with C#, if is possible just the X or Y position.

I tried using

BlockInput(true);

But this will also freeze my keyboard.

Any help?

Upvotes: 0

Views: 814

Answers (5)

user1452079
user1452079

Reputation: 118

Use Cursor.Clip. It will work.

Upvotes: 1

Boldijar Paul
Boldijar Paul

Reputation: 5495

The best solution was to set the mouse sensitivity to 0, it worked perfectly.

Upvotes: 0

Michael27
Michael27

Reputation: 159

You could "simulate" blocked mouse. When mouse position changes you return it to the original starting position you set up before. Use X and Y to set up starting mouse position, like 960,540 (this is half of 1920,1080) and then you handle the mouse move event so that it returns cursor to the original position.

Upvotes: 0

Zaheer Ahmed
Zaheer Ahmed

Reputation: 28578

Here is a nice article to handle keyboard and mouse.

for mouse:

 actHook= new UserActivityHook(); // crate an instance
 actHook.OnMouseActivity+=new MouseEventHandler(MouseMoved);

and then in function do whatever you want:

public void MouseMoved(object sender, MouseEventArgs e)
{
    labelMousePosition.Text=String.Format("x={0}  y={1}", e.X, e.Y);
    if (e.Clicks>0) LogWrite("MouseButton     - " + e.Button.ToString());
}

Upvotes: 0

SLaks
SLaks

Reputation: 887797

Set the Cursor.Clip property to a rectangle to restrict cursor movement.

Upvotes: 1

Related Questions