改变鼠标位置 [英] Change mouse position

查看:102
本文介绍了改变鼠标位置的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有这个代码用于改变鼠标位置,但我想要一些其他的东西如果用户移动鼠标10厘米鼠标移动1厘米在屏幕上所以我知道我必须改变屏幕的分辨率和改变鼠标速度... :( PLZ help







i have this code for change mouse position but i want some thing else if user move mouse 10 cm the mouse move 1 cm on the screen so i know i have to change resolution of screen and change mouse speed ... :( plz help



}
       public Int32 x = 0;
       public Int32 y = 0;
       public Int32 prevx = 0;
       public Int32 prevy = 0;
       private void Form1_Load(object sender, EventArgs e)
       {
           timer1.Interval = 1;
           timer1.Enabled = true;
           x = Cursor.Position.X;
           y = Cursor.Position.Y;
           prevx = Cursor.Position.X;
           prevy = Cursor.Position.Y;

       }

       private void timer1_Tick(object sender, EventArgs e)
       {
           x = Cursor.Position.X;
           y = Cursor.Position.Y;
           textBox1.Text = x.ToString();
           textBox2.Text = y.ToString();
           if (x > prevx)
           {

               if (x -prevx > 10)
               {
                   SetCursorPos(x - 9, y);
                   prevx = x - 9;
               }
           }
           else if (x < prevx)
           {
               if (prevx-x > 10)
               {
                   SetCursorPos(x + 9, y);
                   prevx = x - 9;
               }

           }
           ///////////////////////////////////
           if (y> prevy)
           {
               if (y -prevy > 10)
               {
                   SetCursorPos(x ,y-9);
                   prevy = y - 9;
               }
           }
           else if (y < prevy)
           {
               if (prevy-y > 10)
               {
                   SetCursorPos(x, y+9);
                   prevy = y - 9;
               }

           }

           //////////////////////////////////
       }
   }

推荐答案

您可能正在使用 System.Windows.Forms.Cursor 。 (同样,总是,总是标记你的UI库,比如Forms。)



但它已经可以被移动,因为属性位置是一个读/写属性: http: //msdn.microsoft.com/en-us/library/system.windows.forms.cursor.position.aspx [ ^ ]。



请建议使用P / Invoke杀死代码的平台兼容性。如果这是一个Windows窗体应用程序,它可以在许多平台上执行而无需通过Mono重新编译。单个P / Invoke方法可以立即破坏此功能。



-SA
Chances are you are using System.Windows.Forms.Cursor. (Again, always, always tag your UI library, like "Forms".)

But it already can be moved, because the property Position is a read/write property: http://msdn.microsoft.com/en-us/library/system.windows.forms.cursor.position.aspx[^].

Please be advised that using P/Invoke kills platform compatibility of your code. If this is a Windows Forms application, it can be executed on many platforms without recompilation, via Mono. A single P/Invoke method can break this feature at once.

—SA


这篇关于改变鼠标位置的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆