获取原始鼠标移动数据(不是X和Y) [英] Get raw mouse movement data (not X and Y)

查看:137
本文介绍了获取原始鼠标移动数据(不是X和Y)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述





我目前正在创建一个基于软件的KVM,我需要能够捕获用户鼠标移动的原始数据以及方向。



我已经创建了一个全局键盘和鼠标钩子但到目前为止我只能检索与当前屏幕相关的X和Y值不是我想要的。



我一直在网上搜索,我相信我可能需要点击WM_INPUT消息。



非常感谢任何帮助或建议。

Hi,

I am currently creating a software based KVM and I need to be able to capture the raw data of how a user's mouse has moved and in which direction.

I have already created a global keyboard and mouse hook but so far I am only been able to retrieve the X and Y values in relation to the current screen which is not what I am looking for.

I have been searching online and I believe I may need to tap into a WM_INPUT message.

Any help or advice would be greatly appreciated.

推荐答案

好的,我想我可以做出明智的答案......


您可以使用鼠标的X和Y,这是您的工作:



我会解释这就是:

主机 - 运行服务器应用程序并且鼠标连接到的计算机

客户端 - 鼠标当前所在的计算机



所以,在主持人身上计算机:

当鼠标移动到屏幕边缘时(你应该可以配置什么边缘,因为你可以在左/右或甚至上/下有监视器)然后转移鼠标移动到客户端。您只需要主机上的delta X和Y(例如,鼠标在主机上移动5个单位,在客户端上移动5个单位)。然后将主机上的鼠标移回其起始位置。



在客户端计算机上:

当鼠标移回到主机边缘,让主机鼠标离开边缘而不重置鼠标位置。如果鼠标移动到另一个客户端边缘,则客户端告诉服务器将数据发送到下一个客户端。



所以如果我想用伪代码执行此操作:



==主机==

Ok, I think I can make an intelligent answer...

You can use the X and Y of the mouse, here is what you do:

I'll explain this in terms of:
Host - Computer that the server application runs on and the mouse is connected to
Client - Computer that the mouse is currently on

So, on the host computer:
When the mouse moves to the edge of the screen (you should have this configurable for what edge, as you can have monitors on the left/right or even over/below) you then transfer the mouse movements over to the client. All you need is the delta X and Y on the host (for example the mouse moves 5 units on the host, move it 5 units on the client). You then move the mouse on the host back to its starting position.

On the client computer:
When the mouse moves back to the host edge, let the host mouse move off the edge without resetting the mouse position. If the mouse moves to another client edge, then the client tells the server to send data to the next client.

So if I wanted to do this in pseudo-code:

== Host Computer ==
//In the mouse move hook
    if (Mouse is within X pixels of edge && !on the client)
    {
        Save the current mouse position
        on the client = true
    }
    else if (mouse is within x pixels of edge && on the client)
    {
        get the delta X and delta Y
        move the mouse on the client dX and dY
        move the mouse on the host -dX and -dY
    }




==客户端计算机==



== Client Computer ==

//In the mouse server movement listener
    if (Host tells us to move)
    {
        move the mouse dX and dY
    }

    if (Mouse gets within X pixels of edge of another client)
    {
       tell host to send movements to the next client
    }

    if (Mouse gets within X pixels of host edge)
    {
       tell host to stop sending mouse movements
    }





或类似的东西。它有点复杂,但是如果我写这篇文章的话,那就是我要做的事情。



Or something like that. Its a little more complicated but that's the meat of what I would do if I was writing this.


Ice -

如果我理解你正在尝试创建虚拟KVM。您希望将位于单台计算机上的应用程序中的消息发送到其他计算机。那是对的吗?如果是这种情况,您将需要某种方式与其他计算机进行通信。您可以将旧式WM_MOUSEMOVE消息用于桌面甚至.Net鼠标方法。重要的是沟通。在目标计算机上的应用程序识别出鼠标移动/键盘输入后,您应该能够以递增方式移动鼠标dx / dt,dy / dt。就控制应用程序而言,您可以使用桌面的虚拟表示。这应该给你调整后的坐标。例如,我有3台我想控制的电脑。每个桌面都将在我的winform应用程序中的第一台控制计算机上显示。当我的鼠标悬停在目标计算机桌面图像上时,桌面上的每张图片(我从控制台会话中猜测)都会显示我想要光标的位置。按桌面大小与代表图像的比例缩放坐标。您必须通过图像的位置来偏移本地应用程序的鼠标坐标(例如,如果图像位于我本地应用程序的100,100,我将不得不从缩放之前的目标计算机中减去该图像)。因此,如果桌面是1280 x 1024,我的图像是320 x 356.我必须将坐标除以4.所以如果我从应用程序读取的坐标是120,160代表20 x 4 = 80,60 x 4目标计算机上= 240。您还可以读取相对于图像控件的鼠标坐标。然后使用您正在使用的任何通信方式将这些鼠标移动消息发送到目标计算机。



问候,



Chris
Ice -
If I understand you are trying to create virtual kvm. You want to send messages from your application which is located on a single computer to other computers. Is that right so far? If that is the case you will need some way to communicate with the other computers. You can use old school WM_MOUSEMOVE messages to the desktop or even .Net mouse methods. What is important is the communication. After your application on the target computer recognizes that the mouse movements/keyboard inputs are meant for it, you should be able to move the mouse incrementally dx/dt, dy/dt. As far as the controlling application you can use a virtual representation of the desktop. This should give you the adjusted coordinates. For example, I have 3 computers I want to control. Each of the desktops will be represented on my first controlling computer in my winform application. Each picture (I'm guessing from the console session) of the desktop will show where I want my cursor to be when my mouse hovers over the target computer desktop image. Scale the coordinates by the ratio of the desktop size to representative image. You will have to offset the mouse coordinates of your local application by the location of the image (e.g. if the image is located at 100, 100 on my local application I will have to subtract that from my target computer's coordinated prior to scaling). So if the desktop is 1280 x 1024 and my image is 320 x 356. I would have to divide the coordinates by 4. So if the coordinate I read from application is 120, 160 that would represent 20 x 4 = 80, 60 x 4 = 240 on the target computer. You can also read the mouse coordinates relative to the image control. Then send those mouse move message to the target computer using whatever means of communication you are using.

Regards,

Chris


这篇关于获取原始鼠标移动数据(不是X和Y)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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