如何将光标位置移动到我想要的位置 [英] How can i move the cursor position to a position that I want
本文介绍了如何将光标位置移动到我想要的位置的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
移动鼠标后,我想将鼠标指针移动到原来的位置。
如何将光标位置移动到我想要的位置
解决方案
不幸的是,它可能需要使用P / Invoke: http: //en.wikipedia.org/wiki/PInvoke [ ^ ]。
最全面的方法是使用非常低级别的Windows APISendInput
: http://msdn.microsoft.com/en- us / library / windows / desktop / ms646310%28v = vs.85%29.aspx [ ^ ]。
这是怎么回事通过P / Invoke在.NET中查找: http://www.pinvoke.net/default.aspx/user32.sendinput [ ^ ]。
(非常简单。一切都已经为你完成了。不是很好吗? :-))
更简单的方法是使用SetCursorPos
:
http://msdn.microsoft.com/en-us/ library / windows / desktop / ms648394%28v = vs.85%29.aspx [ ^ ],
http://www.pinvoke.net/default.aspx/user32.setcursorpos [ ^ ]。
(为什么在P / Invoke使用P / Invoke所有,当此功能在 祝你好运,System.Windows.Forms
中可用时:
http://msdn.microsoft.com/en-us/library/system.windows.forms.cursor.position.aspx [ ^ ]。
您可以将此库的引用添加到WPF应用程序并使用它设置光标位置。但是,据我记得,我试过去发现它并不适用于所有情况。为什么?据我所知,当这个API的调用抛出异常时,异常消息清楚地解释了这个问题。很抱歉在这件事情上这么模糊,我现在没时间重复了。如果你想尝试,面对问题,需要进一步解释,我很乐意尝试解释。)
-SA
After i moved the mouse i want to move the mouse pointer to his original position.
How can i move the cursor position to a position that i want
解决方案
Unfortunately, it may require the use of P/Invoke: http://en.wikipedia.org/wiki/PInvoke[^].
The most comprehensive way is the use of the very low-level Windows APISendInput
: http://msdn.microsoft.com/en-us/library/windows/desktop/ms646310%28v=vs.85%29.aspx[^].
This is how it looks in .NET via P/Invoke: http://www.pinvoke.net/default.aspx/user32.sendinput[^].
(Very simple. Everything is already done for you. Isn't that nice? :-))
The simpler way is usingSetCursorPos
:
http://msdn.microsoft.com/en-us/library/windows/desktop/ms648394%28v=vs.85%29.aspx[^],
http://www.pinvoke.net/default.aspx/user32.setcursorpos[^].
(Why using P/Invoke at all, when this functionality is available in Good luck,System.Windows.Forms
:
http://msdn.microsoft.com/en-us/library/system.windows.forms.cursor.position.aspx[^].
You could add a reference to this library to WPF application and set the cursor position using it. But, as far as I remember, I tried it out to find that it does not work in all cases. Why? As far as I remember, when the call of this API throws exception, the exception message clearly explains this problem. Sorry about being so vague in this matter, I just don't have time to repeat it right now. If you want to try, face the problem, and would need further explanation, I'll gladly try to explain it.)
—SA
这篇关于如何将光标位置移动到我想要的位置的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文