简体   繁体   English

在 C# 中移动鼠标 cursor 离屏

[英]moving mouse cursor off screen in C#

I have a wpf window that has a height of 2000 with an actual desktop height of about 1000. Obviously about half of the window is off screen.我有一个 wpf window,它的高度为 2000,实际桌面高度约为 1000。显然,大约一半的 window 不在屏幕上。 Even though the window extends below the screen, the mouse will not move down to that area.即使 window 延伸到屏幕下方,鼠标也不会向下移动到该区域。 I do want this content to be off-screen, and I want the mouse to be able to move over it and click on elements if the mouse is positioned over an element at that position.我确实希望此内容不在屏幕上,并且如果鼠标位于该 position 的元素上,我希望鼠标能够在其上移动并单击元素。 I don't want to change my screen resolution as some content absolutely has to be off the screen.我不想更改我的屏幕分辨率,因为某些内容绝对必须不在屏幕上。 Not sure how to go about this.不知道如何 go 关于这个。

Cursor delimiting is not done by the application, but by Windows itself. Cursor 分隔不是由应用程序完成,而是由 Windows 本身完成。 To my knowledge there is no way to have your cursor pointing off the screen.据我所知,没有办法让您的 cursor 指向屏幕外。

You could simulate what you want by doing what many games do.您可以通过做许多游戏所做的来模拟您想要的。 Do not draw the Windows cursor, draw a custom one in your app window.不要绘制 Windows cursor,在您的应用程序中绘制自定义 window。 Force the real cursor (not being drawn) to stay in the center of the monitor.强制真正的 cursor(未绘制)留在显示器的中心。 Every time the user moves the real cursor, move your application's cursor accordingly and re-place the real cursor to the center of the screen.每次用户移动真正的 cursor 时,相应地移动应用程序的 cursor 并将真正的 cursor 重新放置到屏幕中央。

This will give the illusion of what you'd like, but I don't think WPF can handle this.这会给您带来您想要的错觉,但我不认为 WPF 可以处理这个问题。

I think it is possible.我认为这是可能的。 This program will enable to use a secondary computer as an extra monitor.该程序将允许使用辅助计算机作为额外的监视器。 There are several programs that can let you know the coordinates where your mouse cursor is positioned.有几个程序可以让您知道鼠标 cursor 所在的坐标。 For example AutoIt will do that easily.例如AutoIt很容易做到这一点。

在此处输入图像描述

When you install autoit it comes with this utility that will let you know the cordinates where you position the mouse.当你安装 autoit 时,它附带了这个实用程序,它会让你知道你 position 鼠标的坐标。 When I took the screen capture the mouse does not show up but I draw a blue dot where the mouse was located.当我进行屏幕截图时,鼠标没有出现,但我在鼠标所在的位置画了一个蓝点。 Note that the cordinates where 710, 1464. Right now my screen resolution is 1200 * 1920 (my monitor is rotated).注意坐标是 710, 1464。现在我的屏幕分辨率是 1200 * 1920(我的显示器是旋转的)。 So with Autoit I am able to position my mouse cursor by doing something like因此,使用 Autoit,我可以通过执行类似的操作来 position 我的鼠标 cursor

在此处输入图像描述

When I run that autoit program it will move the mouse to that location.当我运行该 autoit 程序时,它会将鼠标移动到该位置。 The answers to this question seem to be right cause I am not able to move the mouse any further than 1200 to the right.这个问题的答案似乎是正确的,因为我无法将鼠标向右移动超过 1200。 In other words executing MouseMove(2500,800) will result in moving the mouse to 1200,800.换句话说,执行 MouseMove(2500,800) 将导致鼠标移动到 1200,800。 Now the interesting part is how come I am able to move the mouse to (2500,800)!现在有趣的部分是我为什么能够将鼠标移动到(2500,800)! if I use This program In other words executing MouseMove(2500,800) now works with Autoit and the mouse actually moves to the other computer (maxivista has to be running).如果我使用这个程序换句话说,执行MouseMove(2500,800)现在可以与 Autoit 一起使用,并且鼠标实际上会移动到另一台计算机(必须运行 maxivista)。 maxivista shows that there can be a way of moving the mouse outside the resolution of your screen . maxivista 表明有一种方法可以将鼠标移动到屏幕分辨率之外

If you take a look at the screen shots of MaxiVista you'll find a screen shot showing the Device Manager:如果您查看MaxiVista的屏幕截图,您会发现显示设备管理器的屏幕截图:

Device Manager http://www.maxivista.com/pics/screenshots/vista_devicemanager_en.gif设备管理器 http://www.maxivista.com/pics/screenshots/vista_devicemanager_en.gif

As you can see they simply wrote a virtual display adapter, which provides its own display size.如您所见,他们只是编写了一个虚拟显示适配器,它提供了自己的显示大小。 So windows will be informed about a available size of eg 2560x1600 would be possible and allows these bounds for all windows and the mouse.所以 windows 将被告知一个可用的大小,例如 2560x1600 是可能的,并允许所有 windows 和鼠标的这些边界。 Now it is up to the display driver to forward the right portions of this virtual screen to the current real display adapters so that the right part is shown on each physical device.现在由显示驱动程序将此虚拟屏幕的右侧部分转发到当前的真实显示适配器,以便在每个物理设备上显示右侧部分。

There is not an off the screen cursor position in Windows. Windows 中没有屏幕外 cursor position。 I think the mouse is bounded by the screen resolution, even if windows are not.我认为鼠标受屏幕分辨率的限制,即使 windows 不是。

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

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