@@ -713,28 +713,15 @@ ${Object.keys(size)
713
713
const width = Number . parseInt ( match [ isLandscape ? 2 : 1 ] , 10 ) ;
714
714
const height = Number . parseInt ( match [ isLandscape ? 1 : 2 ] , 10 ) ;
715
715
716
- // Use cached device pixel ratio instead of calling getDisplayDensity() every time
717
-
718
- // Convert physical pixels to logical pixels for consistent coordinate system
719
- // adjustCoordinates() will convert back to physical pixels when needed for touch operations
720
- const logicalWidth = Math . round ( width / this . devicePixelRatio ) ;
721
- const logicalHeight = Math . round ( height / this . devicePixelRatio ) ;
722
-
716
+ // Return physical pixels to match screenshot dimensions
717
+ // This ensures AI coordinate conversion uses the same dimensions as the screenshot
723
718
return {
724
- width : logicalWidth ,
725
- height : logicalHeight ,
719
+ width,
720
+ height,
726
721
dpr : this . devicePixelRatio ,
727
722
} ;
728
723
}
729
724
730
- private adjustCoordinates ( x : number , y : number ) : { x : number ; y : number } {
731
- const ratio = this . devicePixelRatio ;
732
- return {
733
- x : Math . round ( x * ratio ) ,
734
- y : Math . round ( y * ratio ) ,
735
- } ;
736
- }
737
-
738
725
/**
739
726
* Calculate the end point for scroll operations based on start point, scroll delta, and screen boundaries.
740
727
* This method ensures that scroll operations stay within screen bounds and maintain a minimum scroll distance
@@ -1183,20 +1170,17 @@ ${Object.keys(size)
1183
1170
async mouseClick ( x : number , y : number ) : Promise < void > {
1184
1171
const adb = await this . getAdb ( ) ;
1185
1172
1186
- // Use adjusted coordinates
1187
- const { x : adjustedX , y : adjustedY } = this . adjustCoordinates ( x , y ) ;
1188
1173
await adb . shell (
1189
- `input${ this . getDisplayArg ( ) } swipe ${ adjustedX } ${ adjustedY } ${ adjustedX } ${ adjustedY } 150` ,
1174
+ `input${ this . getDisplayArg ( ) } swipe ${ x } ${ y } ${ x } ${ y } 150` ,
1190
1175
) ;
1191
1176
}
1192
1177
1193
1178
async mouseDoubleClick ( x : number , y : number ) : Promise < void > {
1194
1179
const adb = await this . getAdb ( ) ;
1195
- const { x : adjustedX , y : adjustedY } = this . adjustCoordinates ( x , y ) ;
1196
1180
1197
1181
// Use input tap for double-click as it generates proper touch events
1198
1182
// that Android can recognize as a double-click gesture
1199
- const tapCommand = `input${ this . getDisplayArg ( ) } tap ${ adjustedX } ${ adjustedY } ` ;
1183
+ const tapCommand = `input${ this . getDisplayArg ( ) } tap ${ x } ${ y } ` ;
1200
1184
await adb . shell ( tapCommand ) ;
1201
1185
// Short delay between taps for double-click recognition
1202
1186
await sleep ( 50 ) ;
@@ -1216,15 +1200,11 @@ ${Object.keys(size)
1216
1200
) : Promise < void > {
1217
1201
const adb = await this . getAdb ( ) ;
1218
1202
1219
- // Use adjusted coordinates
1220
- const { x : fromX , y : fromY } = this . adjustCoordinates ( from . x , from . y ) ;
1221
- const { x : toX , y : toY } = this . adjustCoordinates ( to . x , to . y ) ;
1222
-
1223
1203
// Ensure duration has a default value
1224
1204
const swipeDuration = duration ?? defaultNormalScrollDuration ;
1225
1205
1226
1206
await adb . shell (
1227
- `input${ this . getDisplayArg ( ) } swipe ${ fromX } ${ fromY } ${ toX } ${ toY } ${ swipeDuration } ` ,
1207
+ `input${ this . getDisplayArg ( ) } swipe ${ from . x } ${ from . y } ${ to . x } ${ to . y } ${ swipeDuration } ` ,
1228
1208
) ;
1229
1209
}
1230
1210
@@ -1264,22 +1244,12 @@ ${Object.keys(size)
1264
1244
const endX = startX - deltaX ;
1265
1245
const endY = startY - deltaY ;
1266
1246
1267
- // Adjust coordinates to fit device ratio
1268
- const { x : adjustedStartX , y : adjustedStartY } = this . adjustCoordinates (
1269
- startX ,
1270
- startY ,
1271
- ) ;
1272
- const { x : adjustedEndX , y : adjustedEndY } = this . adjustCoordinates (
1273
- endX ,
1274
- endY ,
1275
- ) ;
1276
-
1277
1247
const adb = await this . getAdb ( ) ;
1278
1248
const swipeDuration = duration ?? defaultNormalScrollDuration ;
1279
1249
1280
1250
// Execute the swipe operation
1281
1251
await adb . shell (
1282
- `input${ this . getDisplayArg ( ) } swipe ${ adjustedStartX } ${ adjustedStartY } ${ adjustedEndX } ${ adjustedEndY } ${ swipeDuration } ` ,
1252
+ `input${ this . getDisplayArg ( ) } swipe ${ startX } ${ startY } ${ endX } ${ endY } ${ swipeDuration } ` ,
1283
1253
) ;
1284
1254
}
1285
1255
@@ -1320,10 +1290,8 @@ ${Object.keys(size)
1320
1290
async longPress ( x : number , y : number , duration = 1000 ) : Promise < void > {
1321
1291
const adb = await this . getAdb ( ) ;
1322
1292
1323
- // Use adjusted coordinates
1324
- const { x : adjustedX , y : adjustedY } = this . adjustCoordinates ( x , y ) ;
1325
1293
await adb . shell (
1326
- `input${ this . getDisplayArg ( ) } swipe ${ adjustedX } ${ adjustedY } ${ adjustedX } ${ adjustedY } ${ duration } ` ,
1294
+ `input${ this . getDisplayArg ( ) } swipe ${ x } ${ y } ${ x } ${ y } ${ duration } ` ,
1327
1295
) ;
1328
1296
}
1329
1297
@@ -1355,13 +1323,9 @@ ${Object.keys(size)
1355
1323
) : Promise < void > {
1356
1324
const adb = await this . getAdb ( ) ;
1357
1325
1358
- // Use adjusted coordinates
1359
- const { x : fromX , y : fromY } = this . adjustCoordinates ( from . x , from . y ) ;
1360
- const { x : toX , y : toY } = this . adjustCoordinates ( to . x , to . y ) ;
1361
-
1362
1326
// Use the specified duration for better pull gesture recognition
1363
1327
await adb . shell (
1364
- `input${ this . getDisplayArg ( ) } swipe ${ fromX } ${ fromY } ${ toX } ${ toY } ${ duration } ` ,
1328
+ `input${ this . getDisplayArg ( ) } swipe ${ from . x } ${ from . y } ${ to . x } ${ to . y } ${ duration } ` ,
1365
1329
) ;
1366
1330
}
1367
1331
0 commit comments