@@ -84,36 +84,23 @@ await SendKeys.SendAsync(inputSimulator =>
84
84
Assert . True ( firstVisibleLine < lastVisibleLine ) ;
85
85
86
86
Point point = await Editor . GetCenterOfEditorOnScreenAsync ( ) ;
87
- TestOutputHelper . WriteLine ( $ "Moving mouse to ({ point . X } , { point . Y } ) and scrolling down.") ;
88
- int horizontalResolution = NativeMethods . GetSystemMetrics ( NativeMethods . SM_CXSCREEN ) ;
89
- int verticalResolution = NativeMethods . GetSystemMetrics ( NativeMethods . SM_CYSCREEN ) ;
90
- point = new ScaleTransform ( 65535.0 / horizontalResolution , 65535.0 / verticalResolution ) . Transform ( point ) ;
91
- TestOutputHelper . WriteLine ( $ "Screen resolution of ({ horizontalResolution } , { verticalResolution } ) translates mouse to ({ point . X } , { point . Y } ).") ;
92
87
93
- await SendKeys . SendAsync ( inputSimulator =>
94
- {
95
- inputSimulator . Mouse
96
- . MoveMouseTo ( point . X , point . Y )
97
- . VerticalScroll ( - 1 ) ;
98
- } ) ;
88
+ await MoveMouseAsync ( point ) ;
89
+ await SendKeys . SendAsync ( inputSimulator => inputSimulator . Mouse . VerticalScroll ( - 1 ) ) ;
99
90
100
91
Assert . Equal ( 0 , await Editor . GetCaretPositionAsync ( ) ) ;
101
92
Assert . Equal ( 3 , await Editor . GetFirstVisibleLineAsync ( ) ) ;
102
93
103
- await SendKeys . SendAsync ( inputSimulator =>
104
- {
105
- inputSimulator . Mouse
106
- . MoveMouseTo ( point . X , point . Y )
107
- . VerticalScroll ( 1 ) ;
108
- } ) ;
94
+ await MoveMouseAsync ( point ) ;
95
+ await SendKeys . SendAsync ( inputSimulator => inputSimulator . Mouse . VerticalScroll ( 1 ) ) ;
109
96
110
97
Assert . Equal ( 0 , await Editor . GetCaretPositionAsync ( ) ) ;
111
98
Assert . Equal ( 0 , await Editor . GetFirstVisibleLineAsync ( ) ) ;
112
99
100
+ await MoveMouseAsync ( point ) ;
113
101
await SendKeys . SendAsync ( inputSimulator =>
114
102
{
115
103
inputSimulator
116
- . Mouse . MoveMouseTo ( point . X , point . Y )
117
104
. Keyboard . KeyDown ( VirtualKeyCode . CONTROL )
118
105
. Mouse . VerticalScroll ( - 1 )
119
106
. Keyboard . Sleep ( 10 ) . KeyUp ( VirtualKeyCode . CONTROL ) ;
@@ -123,10 +110,10 @@ await SendKeys.SendAsync(inputSimulator =>
123
110
Assert . Equal ( 0 , await Editor . GetCaretPositionAsync ( ) ) ;
124
111
Assert . Equal ( expectedLastVisibleLine , await Editor . GetFirstVisibleLineAsync ( ) ) ;
125
112
113
+ await MoveMouseAsync ( point ) ;
126
114
await SendKeys . SendAsync ( inputSimulator =>
127
115
{
128
116
inputSimulator
129
- . Mouse . MoveMouseTo ( point . X , point . Y )
130
117
. Keyboard . KeyDown ( VirtualKeyCode . CONTROL )
131
118
. Mouse . VerticalScroll ( 1 )
132
119
. Keyboard . Sleep ( 10 ) . KeyUp ( VirtualKeyCode . CONTROL ) ;
@@ -176,14 +163,11 @@ await SendKeys.SendAsync(inputSimulator =>
176
163
double zoomLevel = await Editor . GetZoomLevelAsync ( ) ;
177
164
178
165
Point point = await Editor . GetCenterOfEditorOnScreenAsync ( ) ;
179
- int horizontalResolution = NativeMethods . GetSystemMetrics ( NativeMethods . SM_CXSCREEN ) ;
180
- int verticalResolution = NativeMethods . GetSystemMetrics ( NativeMethods . SM_CYSCREEN ) ;
181
- point = new ScaleTransform ( 65535.0 / horizontalResolution , 65535.0 / verticalResolution ) . Transform ( point ) ;
182
166
167
+ await MoveMouseAsync ( point ) ;
183
168
await SendKeys . SendAsync ( inputSimulator =>
184
169
{
185
170
inputSimulator
186
- . Mouse . MoveMouseTo ( point . X , point . Y )
187
171
. Keyboard . KeyDown ( VirtualKeyCode . CONTROL )
188
172
. Mouse . VerticalScroll ( - 1 )
189
173
. Keyboard . Sleep ( 10 ) . KeyUp ( VirtualKeyCode . CONTROL ) ;
@@ -194,10 +178,10 @@ await SendKeys.SendAsync(inputSimulator =>
194
178
Assert . Equal ( expectedLastVisibleLine , await Editor . GetFirstVisibleLineAsync ( ) ) ;
195
179
Assert . Equal ( zoomLevel , await Editor . GetZoomLevelAsync ( ) ) ;
196
180
181
+ await MoveMouseAsync ( point ) ;
197
182
await SendKeys . SendAsync ( inputSimulator =>
198
183
{
199
184
inputSimulator
200
- . Mouse . MoveMouseTo ( point . X , point . Y )
201
185
. Keyboard . KeyDown ( VirtualKeyCode . CONTROL )
202
186
. Mouse . VerticalScroll ( 1 )
203
187
. Keyboard . Sleep ( 10 ) . KeyUp ( VirtualKeyCode . CONTROL ) ;
@@ -209,5 +193,21 @@ await SendKeys.SendAsync(inputSimulator =>
209
193
210
194
window . Close ( vsSaveChanges . vsSaveChangesNo ) ;
211
195
}
196
+
197
+ private async Task MoveMouseAsync ( Point point )
198
+ {
199
+ TestOutputHelper . WriteLine ( $ "Moving mouse to ({ point . X } , { point . Y } ).") ;
200
+ int horizontalResolution = NativeMethods . GetSystemMetrics ( NativeMethods . SM_CXSCREEN ) ;
201
+ int verticalResolution = NativeMethods . GetSystemMetrics ( NativeMethods . SM_CYSCREEN ) ;
202
+ var virtualPoint = new ScaleTransform ( 65535.0 / horizontalResolution , 65535.0 / verticalResolution ) . Transform ( point ) ;
203
+ TestOutputHelper . WriteLine ( $ "Screen resolution of ({ horizontalResolution } , { verticalResolution } ) translates mouse to ({ virtualPoint . X } , { virtualPoint . Y } ).") ;
204
+
205
+ await SendKeys . SendAsync ( inputSimulator => inputSimulator . Mouse . MoveMouseTo ( virtualPoint . X , virtualPoint . Y ) ) ;
206
+
207
+ // ⚠ The call to GetCursorPos is required for correct behavior.
208
+ var actualPoint = NativeMethods . GetCursorPos ( ) ;
209
+ Assert . True ( Math . Abs ( actualPoint . X - point . X ) <= 1 ) ;
210
+ Assert . True ( Math . Abs ( actualPoint . Y - point . Y ) <= 1 ) ;
211
+ }
212
212
}
213
213
}
0 commit comments