简体   繁体   English

C#冻结鼠标移动

[英]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. 我试图用C#禁用鼠标移动,如果可能只是X或Y位置。

I tried using 我试过用

BlockInput(true);

But this will also freeze my keyboard. 但这也会冻结我的键盘。

Any help? 有帮助吗?

Cursor.Clip属性设置为矩形以限制光标移动。

Use Cursor.Clip. 使用Cursor.Clip。 It will work. 它会工作。

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());
}

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. 使用X和Y设置起始鼠标位置 ,如960,540(这是1920,1080的一半),然后处理鼠标移动事件,使其将光标返回到原始位置。

最好的解决方案是将鼠标灵敏度设置为0,它完美地工作。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM