从Windows Form控制系统鼠标属性. [英] Controling system mouse properties from windows Form.

查看:72
本文介绍了从Windows Form控制系统鼠标属性.的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

CodeScientists!

我的项目要求在单击特定按钮后控制所有鼠标功能(光标移动,左键单击,右键单击,速度等),例如"takeControlButton".单击此按钮时,我的应用程序窗口应最小化,并且光标的移动应根据我的应用程序传递的"cursor.position.X"和"cursor.position.Y"(这些点是根据对象的实时跟踪来计算的,例如照相机鼠标).

我的问题是我对C#和"user32.dll" API的编程知识很少.我不知道如何将这些(x,y)值传输到"System.Windows.MouseHandler"方法.

请帮忙...任何相关的文章/代码段/类似的项目/论坛讨论/....什么都可以.

Hi CodeScientists!

My project requires to take control of all mouse functions(cursor movements,left click,right click,speed,etc.) after a particular button is clicked,say "takeControlButton".When this button is clicked my application window should get minimized and the cursor movements should be according the "cursor.position.X" and "cursor.position.Y" passed by my application(the points are calculated from a real time tracking of an object,something like camera mouse).

My problem is my little programming knowledge of C# and "user32.dll" APIs. I don''t know how to transfer these (x,y) values to "System.Windows.MouseHandler" methods.

Please help...any related article/code snippet/similar projects/forum discussion/....just anything.

Thanks for help in advance!

推荐答案

您只需要P/调用一个Windows API:SendInput.它提供与用户和设备驱动程序完全相同的所有鼠标和键盘输入的全面模拟.

我假设您知道如何进行P/Invoke.



附带说明:

考虑改善事件处理技术.这将更易于维护(但是,如果您喜欢我的技术,则不应该使用Designer创建事件;我仍然认为它更好:

You need to P/Invoke only one Windows API: SendInput. It provides comprehensive simulation of all mouse and keyboard input exactly as the user and device drivers would do.

I assume you know how to do P/Invoke.



Just a side note:

Consider improving your event handling technique. This would be more maintainable (but if you like my technique you should not create events using Designer; I still think its better:

MyButton.Click += (sender, eventArgs) => {
   DoWhateverYouWant(); //note: you don't ***have to*** use sender, eventArgs in signature, you just ***can***
};



另请注意,Apply_Click违反了(好的)Microsoft命名约定.

这是我的解释,为什么这种技术更好,代码却更易于维护:
[已解决]如何为C#控件添加事件 [ ^ ].

另请参见:
如何在特定按钮单击时调用keydown事件 [ ^ ].

—SA



Also note that Apply_Click violates (good) Microsoft naming conventions.

Here is my explanation why such technique is better the code is more maintainable:
[Solved] How to add Event for C# Control[^].

See also:
how to call keydown event on particular button click[^].

—SA


这篇关于从Windows Form控制系统鼠标属性.的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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