@@ -471,11 +471,14 @@ ${Object.keys(size)
471
471
get mouse ( ) {
472
472
return {
473
473
click : ( x : number , y : number ) => this . mouseClick ( x , y ) ,
474
- wheel : ( deltaX : number , deltaY : number ) =>
475
- this . mouseWheel ( deltaX , deltaY ) ,
474
+ wheel : ( deltaX : number , deltaY : number , duration ?: number ) =>
475
+ this . mouseWheel ( deltaX , deltaY , duration ) ,
476
476
move : ( x : number , y : number ) => this . mouseMove ( x , y ) ,
477
- drag : ( from : { x : number ; y : number } , to : { x : number ; y : number } ) =>
478
- this . mouseDrag ( from , to ) ,
477
+ drag : (
478
+ from : { x : number ; y : number } ,
479
+ to : { x : number ; y : number } ,
480
+ duration ?: number ,
481
+ ) => this . mouseDrag ( from , to , duration ) ,
479
482
} ;
480
483
}
481
484
@@ -529,30 +532,76 @@ ${Object.keys(size)
529
532
return '' ;
530
533
}
531
534
532
- async scrollUntilTop ( ) : Promise < void > {
535
+ async scrollUntilTop ( startPoint ?: Point ) : Promise < void > {
536
+ if ( startPoint ) {
537
+ const { height } = await this . size ( ) ;
538
+ const start = { x : startPoint . left , y : startPoint . top } ;
539
+ const end = { x : start . x , y : height } ;
540
+
541
+ await repeat ( defaultScrollUntilTimes , ( ) =>
542
+ this . mouseDrag ( start , end , defaultFastScrollDuration ) ,
543
+ ) ;
544
+ await sleep ( 1000 ) ;
545
+ return ;
546
+ }
547
+
533
548
await repeat ( defaultScrollUntilTimes , ( ) =>
534
- this . mouseWheel ( 0 , 9999999 , defaultFastScrollDuration ) ,
549
+ this . mouseWheel ( 0 , - 9999999 , defaultFastScrollDuration ) ,
535
550
) ;
536
551
await sleep ( 1000 ) ;
537
552
}
538
553
539
- async scrollUntilBottom ( ) : Promise < void > {
554
+ async scrollUntilBottom ( startPoint ?: Point ) : Promise < void > {
555
+ if ( startPoint ) {
556
+ const start = { x : startPoint . left , y : startPoint . top } ;
557
+ const end = { x : start . x , y : 0 } ;
558
+
559
+ await repeat ( defaultScrollUntilTimes , ( ) =>
560
+ this . mouseDrag ( start , end , defaultFastScrollDuration ) ,
561
+ ) ;
562
+ await sleep ( 1000 ) ;
563
+ return ;
564
+ }
565
+
540
566
await repeat ( defaultScrollUntilTimes , ( ) =>
541
- this . mouseWheel ( 0 , - 9999999 , defaultFastScrollDuration ) ,
567
+ this . mouseWheel ( 0 , 9999999 , defaultFastScrollDuration ) ,
542
568
) ;
543
569
await sleep ( 1000 ) ;
544
570
}
545
571
546
- async scrollUntilLeft ( ) : Promise < void > {
572
+ async scrollUntilLeft ( startPoint ?: Point ) : Promise < void > {
573
+ if ( startPoint ) {
574
+ const { width } = await this . size ( ) ;
575
+ const start = { x : startPoint . left , y : startPoint . top } ;
576
+ const end = { x : width , y : start . y } ;
577
+
578
+ await repeat ( defaultScrollUntilTimes , ( ) =>
579
+ this . mouseDrag ( start , end , defaultFastScrollDuration ) ,
580
+ ) ;
581
+ await sleep ( 1000 ) ;
582
+ return ;
583
+ }
584
+
547
585
await repeat ( defaultScrollUntilTimes , ( ) =>
548
- this . mouseWheel ( 9999999 , 0 , defaultFastScrollDuration ) ,
586
+ this . mouseWheel ( - 9999999 , 0 , defaultFastScrollDuration ) ,
549
587
) ;
550
588
await sleep ( 1000 ) ;
551
589
}
552
590
553
- async scrollUntilRight ( ) : Promise < void > {
591
+ async scrollUntilRight ( startPoint ?: Point ) : Promise < void > {
592
+ if ( startPoint ) {
593
+ const start = { x : startPoint . left , y : startPoint . top } ;
594
+ const end = { x : 0 , y : start . y } ;
595
+
596
+ await repeat ( defaultScrollUntilTimes , ( ) =>
597
+ this . mouseDrag ( start , end , defaultFastScrollDuration ) ,
598
+ ) ;
599
+ await sleep ( 1000 ) ;
600
+ return ;
601
+ }
602
+
554
603
await repeat ( defaultScrollUntilTimes , ( ) =>
555
- this . mouseWheel ( - 9999999 , 0 , defaultFastScrollDuration ) ,
604
+ this . mouseWheel ( 9999999 , 0 , defaultFastScrollDuration ) ,
556
605
) ;
557
606
await sleep ( 1000 ) ;
558
607
}
@@ -563,13 +612,13 @@ ${Object.keys(size)
563
612
564
613
if ( startPoint ) {
565
614
const start = { x : startPoint . left , y : startPoint . top } ;
566
- const endY = Math . max ( 0 , start . y - scrollDistance ) ;
615
+ const endY = Math . min ( height , start . y + scrollDistance ) ;
567
616
const end = { x : start . x , y : endY } ;
568
617
await this . mouseDrag ( start , end ) ;
569
618
return ;
570
619
}
571
620
572
- await this . mouseWheel ( 0 , scrollDistance ) ;
621
+ await this . mouseWheel ( 0 , - scrollDistance ) ;
573
622
}
574
623
575
624
async scrollDown ( distance ?: number , startPoint ?: Point ) : Promise < void > {
@@ -578,13 +627,13 @@ ${Object.keys(size)
578
627
579
628
if ( startPoint ) {
580
629
const start = { x : startPoint . left , y : startPoint . top } ;
581
- const endY = Math . min ( height , start . y + scrollDistance ) ;
630
+ const endY = Math . max ( 0 , start . y - scrollDistance ) ;
582
631
const end = { x : start . x , y : endY } ;
583
632
await this . mouseDrag ( start , end ) ;
584
633
return ;
585
634
}
586
635
587
- await this . mouseWheel ( 0 , - scrollDistance ) ;
636
+ await this . mouseWheel ( 0 , scrollDistance ) ;
588
637
}
589
638
590
639
async scrollLeft ( distance ?: number , startPoint ?: Point ) : Promise < void > {
@@ -593,13 +642,13 @@ ${Object.keys(size)
593
642
594
643
if ( startPoint ) {
595
644
const start = { x : startPoint . left , y : startPoint . top } ;
596
- const endX = Math . max ( 0 , start . x - scrollDistance ) ;
645
+ const endX = Math . min ( width , start . x + scrollDistance ) ;
597
646
const end = { x : endX , y : start . y } ;
598
647
await this . mouseDrag ( start , end ) ;
599
648
return ;
600
649
}
601
650
602
- await this . mouseWheel ( scrollDistance , 0 ) ;
651
+ await this . mouseWheel ( - scrollDistance , 0 ) ;
603
652
}
604
653
605
654
async scrollRight ( distance ?: number , startPoint ?: Point ) : Promise < void > {
@@ -608,13 +657,13 @@ ${Object.keys(size)
608
657
609
658
if ( startPoint ) {
610
659
const start = { x : startPoint . left , y : startPoint . top } ;
611
- const endX = Math . min ( width , start . x + scrollDistance ) ;
660
+ const endX = Math . max ( 0 , start . x - scrollDistance ) ;
612
661
const end = { x : endX , y : start . y } ;
613
662
await this . mouseDrag ( start , end ) ;
614
663
return ;
615
664
}
616
665
617
- await this . mouseWheel ( - scrollDistance , 0 ) ;
666
+ await this . mouseWheel ( scrollDistance , 0 ) ;
618
667
}
619
668
620
669
private async ensureYadb ( ) {
@@ -723,20 +772,26 @@ ${Object.keys(size)
723
772
private async mouseDrag (
724
773
from : { x : number ; y : number } ,
725
774
to : { x : number ; y : number } ,
775
+ duration ?: number ,
726
776
) : Promise < void > {
727
777
const adb = await this . getAdb ( ) ;
728
778
729
779
// Use adjusted coordinates
730
780
const { x : fromX , y : fromY } = this . adjustCoordinates ( from . x , from . y ) ;
731
781
const { x : toX , y : toY } = this . adjustCoordinates ( to . x , to . y ) ;
732
782
733
- await adb . shell ( `input swipe ${ fromX } ${ fromY } ${ toX } ${ toY } 300` ) ;
783
+ // Ensure duration has a default value
784
+ const swipeDuration = duration ?? 300 ;
785
+
786
+ await adb . shell (
787
+ `input swipe ${ fromX } ${ fromY } ${ toX } ${ toY } ${ swipeDuration } ` ,
788
+ ) ;
734
789
}
735
790
736
791
private async mouseWheel (
737
792
deltaX : number ,
738
793
deltaY : number ,
739
- duration = defaultNormalScrollDuration ,
794
+ duration ?: number ,
740
795
) : Promise < void > {
741
796
const { width, height } = await this . size ( ) ;
742
797
@@ -758,8 +813,11 @@ ${Object.keys(size)
758
813
deltaY = Math . max ( - maxNegativeDeltaY , Math . min ( deltaY , maxPositiveDeltaY ) ) ;
759
814
760
815
// Calculate the end coordinates
761
- const endX = startX + deltaX ;
762
- const endY = startY + deltaY ;
816
+ // Note: For swipe, we need to reverse the delta direction
817
+ // because positive deltaY should scroll up (show top content),
818
+ // which requires swiping from bottom to top (decreasing Y)
819
+ const endX = startX - deltaX ;
820
+ const endY = startY - deltaY ;
763
821
764
822
// Adjust coordinates to fit device ratio
765
823
const { x : adjustedStartX , y : adjustedStartY } = this . adjustCoordinates (
@@ -773,9 +831,12 @@ ${Object.keys(size)
773
831
774
832
const adb = await this . getAdb ( ) ;
775
833
834
+ // Ensure duration has a default value
835
+ const swipeDuration = duration ?? defaultNormalScrollDuration ;
836
+
776
837
// Execute the swipe operation
777
838
await adb . shell (
778
- `input swipe ${ adjustedStartX } ${ adjustedStartY } ${ adjustedEndX } ${ adjustedEndY } ${ duration } ` ,
839
+ `input swipe ${ adjustedStartX } ${ adjustedStartY } ${ adjustedEndX } ${ adjustedEndY } ${ swipeDuration } ` ,
779
840
) ;
780
841
}
781
842
0 commit comments