【问题标题】:How do I map my phone's screen coordinates to my pc screen?如何将手机的屏幕坐标映射到我的电脑屏幕?
【发布时间】:2013-04-01 01:57:11
【问题描述】:

我终于开发了我的应用程序,我可以用我的 Android 手机控制 PC 鼠标。我正在使用触摸屏来控制鼠标。

问题是鼠标光标只能在手机屏幕尺寸限制的特定区域内移动。我希望能够到处移动光标?我需要某种映射吗?

这就是我通过手机发送坐标的方式:

public boolean onTouchEvent(MotionEvent evt)
{   
    String coords = Math.round(evt.getX()) + ", " + Math.round(evt.getY());

    Log.d(TAG, coords);

    msgIO.sendMessage(soc, coords);

    return true;
}

澄清: 假设手机屏幕限制为 300x700,PC 屏幕限制为 1080x720。现在,如果我使用手机的触摸屏发送坐标,它只会将鼠标光标移动到 300x700 矩形内的 pc 端。我想在 1080x720 矩形内移动它。

【问题讨论】:

  • 如果您需要任何帮助,必须提供更多信息。请您解释一下您目前的工作情况如何?
  • 你不得不为此开发一个应用程序太糟糕了,有一个开源项目可以做到这一点(由谷歌员工编写),它可以让你在整个屏幕上移动光标电脑。
  • 我知道有一个应用程序。我想亲自尝试以理解这些概念。

标签: android coordinates mouse screen-resolution


【解决方案1】:

我想你可以用数学解决它。

您需要向PC发送4个参数。

String coords = Phone_Touched_X;
coords += ", "
coords += Phone_Touched_Y
coords += ", "
coords += Phone_Screen_X
coords += ", "
coords += Phone_Screen_Y

PC端:

Position_X = PC_Screen_X * Phone_Touched_X / Phone_Screen_X;
Position_Y = PC_Screen_Y * Phone_Touched_Y / Phone_Screen_Y;

例子:

您在 300x700 的手机屏幕上触摸了 200,200。并将其发送到 1080x720 的 PC。

Position_X = 1080 * 200 / 300 = 720
Position_Y = 720 * 200 / 700 = 205

请注意,您还需要考虑是否以纵向模式操作手机。 在这种情况下,您应该传递 700x300 而不是 300x700。

Position_X = 1080 * 200 / 700 = 308
Position_Y = 720 * 200 / 300 = 480

【讨论】:

    猜你喜欢
    • 2016-08-02
    • 1970-01-01
    • 1970-01-01
    • 2012-12-09
    • 1970-01-01
    • 1970-01-01
    • 2023-03-31
    • 1970-01-01
    • 2016-10-09
    相关资源
    最近更新 更多