mirror of
https://github.com/barry-ran/QtScrcpy.git
synced 2025-04-25 05:55:01 +00:00
feat: optimize drag and add tiktok map
This commit is contained in:
parent
afa5e508f8
commit
06cdb345bb
8 changed files with 109 additions and 26 deletions
|
@ -42,9 +42,8 @@ void InputConvertGame::mouseEvent(const QMouseEvent *from, const QSize &frameSiz
|
||||||
if (processMouseClick(from)) {
|
if (processMouseClick(from)) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
} else {
|
|
||||||
InputConvertNormal::mouseEvent(from, frameSize, showSize);
|
|
||||||
}
|
}
|
||||||
|
InputConvertNormal::mouseEvent(from, frameSize, showSize);
|
||||||
}
|
}
|
||||||
|
|
||||||
void InputConvertGame::wheelEvent(const QWheelEvent *from, const QSize &frameSize, const QSize &showSize)
|
void InputConvertGame::wheelEvent(const QWheelEvent *from, const QSize &frameSize, const QSize &showSize)
|
||||||
|
@ -117,7 +116,7 @@ void InputConvertGame::loadKeyMap(const QString &json)
|
||||||
void InputConvertGame::updateSize(const QSize &frameSize, const QSize &showSize)
|
void InputConvertGame::updateSize(const QSize &frameSize, const QSize &showSize)
|
||||||
{
|
{
|
||||||
if (showSize != m_showSize) {
|
if (showSize != m_showSize) {
|
||||||
if (m_gameMap) {
|
if (m_gameMap && m_keyMap.isValidMouseMoveMap()) {
|
||||||
// show size change, resize grab cursor
|
// show size change, resize grab cursor
|
||||||
emit grabCursor(true);
|
emit grabCursor(true);
|
||||||
}
|
}
|
||||||
|
@ -296,10 +295,14 @@ void InputConvertGame::processKeyClick(
|
||||||
|
|
||||||
void InputConvertGame::processKeyDrag(const QPointF& startPos, QPointF endPos, const QKeyEvent* from)
|
void InputConvertGame::processKeyDrag(const QPointF& startPos, QPointF endPos, const QKeyEvent* from)
|
||||||
{
|
{
|
||||||
if(QEvent::KeyPress == from->type()){
|
if (QEvent::KeyPress == from->type()){
|
||||||
int id = attachTouchID(from->key());
|
int id = attachTouchID(from->key());
|
||||||
sendTouchDownEvent(id, startPos);
|
sendTouchDownEvent(id, startPos);
|
||||||
sendTouchMoveEvent(id, endPos);
|
sendTouchMoveEvent(id, endPos);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (QEvent::KeyRelease == from->type()) {
|
||||||
|
int id = getTouchID(from->key());
|
||||||
sendTouchUpEvent(id, endPos);
|
sendTouchUpEvent(id, endPos);
|
||||||
detachTouchID(from->key());
|
detachTouchID(from->key());
|
||||||
}
|
}
|
||||||
|
@ -314,16 +317,19 @@ bool InputConvertGame::processMouseClick(const QMouseEvent *from)
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
qDebug() << "mouse event " << from->type();
|
||||||
if (QEvent::MouseButtonPress == from->type() || QEvent::MouseButtonDblClick == from->type()) {
|
if (QEvent::MouseButtonPress == from->type() || QEvent::MouseButtonDblClick == from->type()) {
|
||||||
int id = attachTouchID(from->button());
|
int id = attachTouchID(from->button());
|
||||||
sendTouchDownEvent(id, node.data.click.keyNode.pos);
|
sendTouchDownEvent(id, node.data.click.keyNode.pos);
|
||||||
} else if (QEvent::MouseButtonRelease == from->type()) {
|
return true;
|
||||||
sendTouchUpEvent(getTouchID(from->button()), node.data.click.keyNode.pos);
|
|
||||||
detachTouchID(from->button());
|
|
||||||
} else {
|
|
||||||
return false;
|
|
||||||
}
|
}
|
||||||
return true;
|
if (QEvent::MouseButtonRelease == from->type()) {
|
||||||
|
int id = getTouchID(from->button());
|
||||||
|
sendTouchUpEvent(id, node.data.click.keyNode.pos);
|
||||||
|
detachTouchID(from->button());
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool InputConvertGame::processMouseMove(const QMouseEvent *from)
|
bool InputConvertGame::processMouseMove(const QMouseEvent *from)
|
||||||
|
@ -433,6 +439,12 @@ void InputConvertGame::stopMouseMoveTimer()
|
||||||
bool InputConvertGame::switchGameMap()
|
bool InputConvertGame::switchGameMap()
|
||||||
{
|
{
|
||||||
m_gameMap = !m_gameMap;
|
m_gameMap = !m_gameMap;
|
||||||
|
|
||||||
|
if (!m_keyMap.isValidMouseMoveMap()) {
|
||||||
|
return m_gameMap;
|
||||||
|
}
|
||||||
|
|
||||||
|
// grab cursor and set cursor only mouse move map
|
||||||
emit grabCursor(m_gameMap);
|
emit grabCursor(m_gameMap);
|
||||||
if (m_gameMap) {
|
if (m_gameMap) {
|
||||||
#ifdef QT_NO_DEBUG
|
#ifdef QT_NO_DEBUG
|
||||||
|
@ -441,8 +453,6 @@ bool InputConvertGame::switchGameMap()
|
||||||
QGuiApplication::setOverrideCursor(QCursor(Qt::CrossCursor));
|
QGuiApplication::setOverrideCursor(QCursor(Qt::CrossCursor));
|
||||||
#endif
|
#endif
|
||||||
} else {
|
} else {
|
||||||
if(m_ctrlMouseMove.touching)
|
|
||||||
mouseMoveStopTouch();
|
|
||||||
QGuiApplication::restoreOverrideCursor();
|
QGuiApplication::restoreOverrideCursor();
|
||||||
}
|
}
|
||||||
return m_gameMap;
|
return m_gameMap;
|
||||||
|
|
|
@ -134,7 +134,7 @@ void KeyMap::loadKeyMap(const QString &json)
|
||||||
case KeyMap::KMT_CLICK_TWICE:
|
case KeyMap::KMT_CLICK_TWICE:
|
||||||
{
|
{
|
||||||
// safe check
|
// safe check
|
||||||
if (!checkForClickDouble(node)) {
|
if (!checkForClickTwice(node)) {
|
||||||
qWarning() << "json error: keyMapNodes node format error";
|
qWarning() << "json error: keyMapNodes node format error";
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
@ -386,12 +386,12 @@ bool KeyMap::checkItemDouble(const QJsonObject& node, const QString& name)
|
||||||
|
|
||||||
bool KeyMap::checkItemBool(const QJsonObject& node, const QString& name)
|
bool KeyMap::checkItemBool(const QJsonObject& node, const QString& name)
|
||||||
{
|
{
|
||||||
return !node.contains(name) || node.value(name).isBool();
|
return node.contains(name) && node.value(name).isBool();
|
||||||
}
|
}
|
||||||
|
|
||||||
bool KeyMap::checkItemObject(const QJsonObject &node, const QString &name)
|
bool KeyMap::checkItemObject(const QJsonObject &node, const QString &name)
|
||||||
{
|
{
|
||||||
return !node.contains(name) || node.value(name).isObject();
|
return node.contains(name) && node.value(name).isObject();
|
||||||
}
|
}
|
||||||
|
|
||||||
bool KeyMap::checkItemPos(const QJsonObject& node, const QString& name)
|
bool KeyMap::checkItemPos(const QJsonObject& node, const QString& name)
|
||||||
|
@ -406,13 +406,12 @@ bool KeyMap::checkItemPos(const QJsonObject& node, const QString& name)
|
||||||
|
|
||||||
bool KeyMap::checkForClick(const QJsonObject& node)
|
bool KeyMap::checkForClick(const QJsonObject& node)
|
||||||
{
|
{
|
||||||
return checkItemString(node, "key") && checkItemPos(node, "pos")
|
return checkForClickTwice(node) && checkItemBool(node, "switchMap");
|
||||||
&& checkItemBool(node, "switchMap");
|
|
||||||
}
|
}
|
||||||
|
|
||||||
bool KeyMap::checkForClickDouble(const QJsonObject& node)
|
bool KeyMap::checkForClickTwice(const QJsonObject& node)
|
||||||
{
|
{
|
||||||
return checkForClick(node);
|
return checkItemString(node, "key") && checkItemPos(node, "pos");
|
||||||
}
|
}
|
||||||
|
|
||||||
bool KeyMap::checkForSteerWhell(const QJsonObject& node)
|
bool KeyMap::checkForSteerWhell(const QJsonObject& node)
|
||||||
|
|
|
@ -95,7 +95,7 @@ private:
|
||||||
|
|
||||||
// safe check for KeyMapNode
|
// safe check for KeyMapNode
|
||||||
bool checkForClick(const QJsonObject& node);
|
bool checkForClick(const QJsonObject& node);
|
||||||
bool checkForClickDouble(const QJsonObject& node);
|
bool checkForClickTwice(const QJsonObject& node);
|
||||||
bool checkForSteerWhell(const QJsonObject& node);
|
bool checkForSteerWhell(const QJsonObject& node);
|
||||||
bool checkForDrag(const QJsonObject& node);
|
bool checkForDrag(const QJsonObject& node);
|
||||||
|
|
||||||
|
|
|
@ -32,7 +32,7 @@ It focuses on:
|
||||||
## Customized key mapping (Windows only)
|
## Customized key mapping (Windows only)
|
||||||
You can write your own script to map keyboard and mouse actions to touches and clicks of the mobile phone according to your needs. [Here](docs/按键映射说明.md) are the rules.
|
You can write your own script to map keyboard and mouse actions to touches and clicks of the mobile phone according to your needs. [Here](docs/按键映射说明.md) are the rules.
|
||||||
|
|
||||||
A script for "PUBG mobile" mapping is provided by default. Once enabled, you can play the game with your keyboard and mouse as the PC version. You can also write your own mapping files for other games according to [writing rules](docs/按键映射说明.md). The default key mapping is as follows:
|
A script for "PUBG mobile" and TikTok mapping is provided by default. Once enabled, you can play the game with your keyboard and mouse as the PC version. or you can use up/down/left/right direction keys to simulate up/down/left/right sliding. You can also write your own mapping files for other games according to [writing rules](docs/按键映射说明.md). The default key mapping is as follows:
|
||||||
|
|
||||||

|

|
||||||
|
|
||||||
|
|
|
@ -33,7 +33,7 @@ QtScrcpy可以通过USB(或通过TCP/IP)连接Android设备,并进行显示和
|
||||||
## 自定义按键映射(仅windows平台开启)
|
## 自定义按键映射(仅windows平台开启)
|
||||||
可以根据需要,自己编写脚本将PC键盘按键映射为手机的触摸点击,编写规则在[这里](docs/按键映射说明.md)。
|
可以根据需要,自己编写脚本将PC键盘按键映射为手机的触摸点击,编写规则在[这里](docs/按键映射说明.md)。
|
||||||
|
|
||||||
默认自带了针对和平精英手游进行键鼠映射的映射脚本,开启后可以用键鼠像玩端游一样玩和平精英手游,你也可以按照[编写规则](docs/按键映射说明.md)编写其他游戏的映射文件,默认按键映射如下:
|
默认自带了针对和平精英手游和抖音进行键鼠映射的映射脚本,开启平精英手游后可以用键鼠像玩端游一样玩和平精英手游,开启抖音映射以后可以使用上下左右方向键模拟上下左右滑动,你也可以按照[编写规则](docs/按键映射说明.md)编写其他游戏的映射文件,默认按键映射如下:
|
||||||
|
|
||||||

|

|
||||||
|
|
||||||
|
|
|
@ -16,7 +16,7 @@
|
||||||
|
|
||||||
- switchKey:切换自定义按键映射的开关键,默认为普通映射,需要使用这个按键在普通映射和自定义映射之间切换。
|
- switchKey:切换自定义按键映射的开关键,默认为普通映射,需要使用这个按键在普通映射和自定义映射之间切换。
|
||||||
|
|
||||||
- mouseMoveMap:鼠标移动映射,鼠标的移动将被映射为以startPos为起点,以鼠标移动方向为移动方向的手指拖动操作。
|
- mouseMoveMap:鼠标移动映射,鼠标的移动将被映射为以startPos为起点,以鼠标移动方向为移动方向的手指拖动操作(开启鼠标移动映射以后会隐藏鼠标,限制鼠标移动范围)。
|
||||||
一般在FPS手游中用来调整人物视野。
|
一般在FPS手游中用来调整人物视野。
|
||||||
- startPos 手指拖动起始点
|
- startPos 手指拖动起始点
|
||||||
- speedRatio 鼠标移动映射为手指拖动的比例,可以控制鼠标灵敏度
|
- speedRatio 鼠标移动映射为手指拖动的比例,可以控制鼠标灵敏度
|
||||||
|
@ -26,8 +26,9 @@
|
||||||
一般按键映射有如下几种类型:
|
一般按键映射有如下几种类型:
|
||||||
|
|
||||||
- type 按键映射的类型,每个keyMapNodes中的元素都需要指明,可以是如下类型:
|
- type 按键映射的类型,每个keyMapNodes中的元素都需要指明,可以是如下类型:
|
||||||
- KMT_CLICK 普通点击,键盘按下模拟为手指按下,键盘抬起映射为手指抬起
|
- KMT_CLICK 普通点击,按键按下模拟为手指按下,按键抬起模拟为手指抬起
|
||||||
- KMT_CLICK_TWICE 两次点击,键盘按下模拟为手指按下再抬起,键盘抬起映射为手指按下再抬起
|
- KMT_CLICK_TWICE 两次点击,按键按下模拟为手指按下再抬起,按键抬起模拟为手指按下再抬起
|
||||||
|
- KMT_DRAG 拖拽,按键按下模拟为手指按下并拖动一段距离,按键抬起模拟为手指抬起
|
||||||
- KMT_STEER_WHEEL 方向盘映射,专用于FPS游戏中移动人物脚步的方向盘的映射,需要4个按键来配合。
|
- KMT_STEER_WHEEL 方向盘映射,专用于FPS游戏中移动人物脚步的方向盘的映射,需要4个按键来配合。
|
||||||
|
|
||||||
不同按键映射类型的专有属性说明:
|
不同按键映射类型的专有属性说明:
|
||||||
|
@ -41,6 +42,11 @@
|
||||||
- key 要映射的按键码
|
- key 要映射的按键码
|
||||||
- pos 模拟触摸的位置
|
- pos 模拟触摸的位置
|
||||||
|
|
||||||
|
- KMT_DRAG
|
||||||
|
- key 要映射的按键码
|
||||||
|
- startPos 模拟触摸拖动的开始位置
|
||||||
|
- endPos 模拟触摸拖动的结束位置
|
||||||
|
|
||||||
- KMT_STEER_WHEEL
|
- KMT_STEER_WHEEL
|
||||||
- centerPos 方向盘中心点
|
- centerPos 方向盘中心点
|
||||||
- leftKey 左方向的按键控制
|
- leftKey 左方向的按键控制
|
||||||
|
|
|
@ -7,7 +7,8 @@
|
||||||
},
|
},
|
||||||
"speedRatio": 10
|
"speedRatio": 10
|
||||||
},
|
},
|
||||||
"keyMapNodes": [{
|
"keyMapNodes": [
|
||||||
|
{
|
||||||
"comment": "方向盘",
|
"comment": "方向盘",
|
||||||
"type": "KMT_STEER_WHEEL",
|
"type": "KMT_STEER_WHEEL",
|
||||||
"centerPos": {
|
"centerPos": {
|
||||||
|
|
67
keymap/tiktok.json
Normal file
67
keymap/tiktok.json
Normal file
|
@ -0,0 +1,67 @@
|
||||||
|
{
|
||||||
|
"switchKey": "Key_QuoteLeft",
|
||||||
|
"keyMapNodes": [
|
||||||
|
{
|
||||||
|
"comment": "暂停/继续",
|
||||||
|
"type": "KMT_CLICK",
|
||||||
|
"key": "Key_Space",
|
||||||
|
"pos": {
|
||||||
|
"x": 0.5,
|
||||||
|
"y": 0.5
|
||||||
|
},
|
||||||
|
"switchMap": false
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"comment": "上滑",
|
||||||
|
"type": "KMT_DRAG",
|
||||||
|
"key": "Key_Up",
|
||||||
|
"startPos": {
|
||||||
|
"x": 0.5,
|
||||||
|
"y": 0.7
|
||||||
|
},
|
||||||
|
"endPos": {
|
||||||
|
"x": 0.5,
|
||||||
|
"y": 0.3
|
||||||
|
}
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"comment": "下滑",
|
||||||
|
"type": "KMT_DRAG",
|
||||||
|
"key": "Key_Down",
|
||||||
|
"startPos": {
|
||||||
|
"x": 0.5,
|
||||||
|
"y": 0.3
|
||||||
|
},
|
||||||
|
"endPos": {
|
||||||
|
"x": 0.5,
|
||||||
|
"y": 0.7
|
||||||
|
}
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"comment": "左滑",
|
||||||
|
"type": "KMT_DRAG",
|
||||||
|
"key": "Key_Left",
|
||||||
|
"startPos": {
|
||||||
|
"x": 0.7,
|
||||||
|
"y": 0.5
|
||||||
|
},
|
||||||
|
"endPos": {
|
||||||
|
"x": 0.3,
|
||||||
|
"y": 0.5
|
||||||
|
}
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"comment": "右滑",
|
||||||
|
"type": "KMT_DRAG",
|
||||||
|
"key": "Key_Right",
|
||||||
|
"startPos": {
|
||||||
|
"x": 0.3,
|
||||||
|
"y": 0.5
|
||||||
|
},
|
||||||
|
"endPos": {
|
||||||
|
"x": 0.7,
|
||||||
|
"y": 0.5
|
||||||
|
}
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
Loading…
Add table
Reference in a new issue