diff --git a/QtScrcpy/device/controller/inputconvert/inputconvertgame.cpp b/QtScrcpy/device/controller/inputconvert/inputconvertgame.cpp index 0624462..5278cfb 100644 --- a/QtScrcpy/device/controller/inputconvert/inputconvertgame.cpp +++ b/QtScrcpy/device/controller/inputconvert/inputconvertgame.cpp @@ -395,8 +395,9 @@ bool InputConvertGame::processMouseMove(const QMouseEvent *from) } if (!m_ctrlMouseMove.lastPos.isNull() && m_processMouseMove) { - QPointF distance = from->localPos() - m_ctrlMouseMove.lastPos; - distance /= m_keyMap.getMouseMoveMap().data.mouseMove.speedRatio; + QPointF distance_raw{from->localPos() - m_ctrlMouseMove.lastPos}; + QPointF speedRatio {m_keyMap.getMouseMoveMap().data.mouseMove.speedRatio}; + QPointF distance {distance_raw.x() / speedRatio.x(), distance_raw.y() / speedRatio.y()}; mouseMoveStartTouch(from); startMouseMoveTimer(); diff --git a/QtScrcpy/device/controller/inputconvert/keymap/keymap.cpp b/QtScrcpy/device/controller/inputconvert/keymap/keymap.cpp index 7190901..c33ee01 100644 --- a/QtScrcpy/device/controller/inputconvert/keymap/keymap.cpp +++ b/QtScrcpy/device/controller/inputconvert/keymap/keymap.cpp @@ -64,11 +64,38 @@ void KeyMap::loadKeyMap(const QString &json) KeyMapNode keyMapNode; keyMapNode.type = KMT_MOUSE_MOVE; - if (!checkItemDouble(mouseMoveMap, "speedRatio")) { - errorString = QString("json error: mouseMoveMap on find speedRatio"); + bool have_speedRatio = false; + + // General speedRatio (for backwards compatibility) + if (checkItemDouble(mouseMoveMap, "speedRatio")) { + float ratio = static_cast(getItemDouble(mouseMoveMap, "speedRatio")); + keyMapNode.data.mouseMove.speedRatio.setX(ratio); + keyMapNode.data.mouseMove.speedRatio.setY(ratio / 2.25f); // Phone screens are often FHD+ + have_speedRatio = true; + } + + // Individual X Ratio + if (checkItemDouble(mouseMoveMap, "speedRatioX")) { + keyMapNode.data.mouseMove.speedRatio.setX(static_cast(getItemDouble(mouseMoveMap, "speedRatioX"))); + have_speedRatio = true; + } + + // Individual Y Ratio + if (checkItemDouble(mouseMoveMap, "speedRatioY")) { + keyMapNode.data.mouseMove.speedRatio.setY(static_cast(getItemDouble(mouseMoveMap, "speedRatioY"))); + have_speedRatio = true; + } + + if (!have_speedRatio) { + errorString = QString("json error: speedRatio setting is missing in mouseMoveMap!"); + goto parseError; + } + + // Sanity check: No ratio must be lower than 0.001 + if ( ( keyMapNode.data.mouseMove.speedRatio.x() < 0.001f ) || ( keyMapNode.data.mouseMove.speedRatio.x() < 0.001f ) ) { + errorString = QString("json error: Minimum speedRatio is 0.001"); goto parseError; } - keyMapNode.data.mouseMove.speedRatio = static_cast(getItemDouble(mouseMoveMap, "speedRatio")); if (!checkItemObject(mouseMoveMap, "startPos")) { errorString = QString("json error: mouseMoveMap on find startPos"); diff --git a/QtScrcpy/device/controller/inputconvert/keymap/keymap.h b/QtScrcpy/device/controller/inputconvert/keymap/keymap.h index 8cf92b7..6b88732 100644 --- a/QtScrcpy/device/controller/inputconvert/keymap/keymap.h +++ b/QtScrcpy/device/controller/inputconvert/keymap/keymap.h @@ -91,8 +91,8 @@ public: } drag; struct { - QPointF startPos = { 0.0, 0.0 }; - int speedRatio = 1; + QPointF startPos = { 0.0, 0.0 }; + QPointF speedRatio = { 1.0, 1.0 }; KeyNode smallEyes; } mouseMove; DATA() {} diff --git a/docs/KeyMapDes.md b/docs/KeyMapDes.md index d9fabd3..bd896cd 100644 --- a/docs/KeyMapDes.md +++ b/docs/KeyMapDes.md @@ -25,7 +25,9 @@ Taking the upper left corner of the screen as the origin, the position of the pi -mouseMoveMap: mouse movement mapping, the movement of the mouse will be mapped to startPos as the starting point, and the direction of the mouse movement as the direction of the finger drag operation (after the mouse movement map is turned on, the mouse will be hidden, limiting the range of mouse movement). Generally used to adjust the character field of vision in FPS mobile games. -startPos finger drag starting point - -speedRatio mouse movement is mapped to the ratio of finger dragging, you can control the mouse sensitivity, the value should be greater than 0.00, the greater the value, the lower the sensitivity + -speedRatio mouse sensitivity of the finger dragging. The value must be at least 0.00225. The greater the value, the lower the sensitivity. The Y-axis translates with a ratio of 2.25. If this does not fit your phone screen, please use the following two settings to set individual sensitivity values. + -speedRatioX sensitivity of the mouse X-axis. This value must be at least 0.001. + -speedRatioY sensitivity of the mouse Y-axis. This value must be at least 0.001. -smallEyes The button that triggers the small eyes. After pressing this button, the mouse movement will be mapped to the finger drag operation with the smallEyes.pos as the starting point and the mouse movement direction as the movement direction -keyMapNodes general key map, json array, all general key maps are placed in this array, map the keys of the keyboard to ordinary finger clicks. @@ -68,4 +70,4 @@ Description of the unique attributes of different key mapping types: -leftOffset After dragging the left arrow key, drag to the leftOffset horizontally to the centerPos -rightOffset After pressing the right direction key, drag it to the right offset of the center to the right of the centerPos position -upOffset After pressing the up arrow key, drag it to the upper offset position horizontally relative to the centerPos position - -downOffset Press the down arrow key and drag it to the downOffset position horizontally relative to the centerPos position \ No newline at end of file + -downOffset Press the down arrow key and drag it to the downOffset position horizontally relative to the centerPos position diff --git a/keymap/FRAG.json b/keymap/FRAG.json new file mode 100644 index 0000000..1150af3 --- /dev/null +++ b/keymap/FRAG.json @@ -0,0 +1,119 @@ +{ + "old-switchKey": "Key_QuoteLeft", + "switchKey": "RightButton", + "mouseMoveMap": { + "startPos": { + "x": 0.5, + "y": 0.5 + }, + "speedRatioX": 3.25, + "speedRatioY": 1.25 + }, + "keyMapNodes": [{ + "comment": "Steering Wheel", + "type": "KMT_STEER_WHEEL", + "centerPos": { + "x": 0.194792, + "y": 0.716484 + }, + "leftOffset": 0.15, + "rightOffset": 0.15, + "upOffset": 0.15, + "downOffset": 0.15, + "leftKey": "Key_A", + "rightKey": "Key_D", + "upKey": "Key_W", + "downKey": "Key_S" + }, + { + "comment": "Activate item under crosshair", + "type": "KMT_CLICK", + "key": "LeftButton", + "pos": { + "x": 0.51875, + "y": 0.496703 + }, + "switchMap": false + }, + { + "comment": "Activate first special skill", + "type": "KMT_CLICK", + "key": "Key_E", + "pos": { + "x": 0.909375, + "y": 0.542857 + }, + "switchMap": false + }, + { + "comment": "Activate Chat", + "type": "KMT_CLICK", + "key": "Key_C", + "pos": { + "x": 0.905208, + "y": 0.254945 + }, + "switchMap": false + }, + { + "comment": "Chat option 1", + "type": "KMT_CLICK", + "key": "Key_1", + "pos": { + "x": 0.875, + "y": 0.523077 + }, + "switchMap": false + }, + { + "comment": "Chat option 2", + "type": "KMT_CLICK", + "key": "Key_2", + "pos": { + "x": 0.875, + "y": 0.606593 + }, + "switchMap": false + }, + { + "comment": "Chat option 3", + "type": "KMT_CLICK", + "key": "Key_3", + "pos": { + "x": 0.875, + "y": 0.685714 + }, + "switchMap": false + }, + { + "comment": "Chat option 4", + "type": "KMT_CLICK", + "key": "Key_4", + "pos": { + "x": 0.875, + "y": 0.756044 + }, + "switchMap": false + }, + { + "comment": "Chat option 5", + "type": "KMT_CLICK", + "key": "Key_5", + "pos": { + "x": 0.875, + "y": 0.832967 + }, + "switchMap": false + }, + { + "comment": "Chat option 6", + "type": "KMT_CLICK", + "key": "Key_6", + "pos": { + "x": 0.875, + "y": 0.911273 + }, + "switchMap": false + } + ] +}