@@ -64,10 +64,15 @@ void MessageInput::restore_cursor_pos()
6464 }
6565}
6666
67- void MessageInput::set_cursor_to_client_pos (int x, int y)
67+ LPARAM MessageInput::prepare_mouse_position (int x, int y)
6868{
69- POINT screen_pos = client_to_screen (x, y);
70- SetCursorPos (screen_pos.x , screen_pos.y );
69+ if (with_cursor_pos_) {
70+ // Genshin 模式:移动真实光标到目标位置
71+ POINT screen_pos = client_to_screen (x, y);
72+ SetCursorPos (screen_pos.x , screen_pos.y );
73+ std::this_thread::sleep_for (std::chrono::milliseconds (1 ));
74+ }
75+ return MAKELPARAM (x, y);
7176}
7277
7378MaaControllerFeature MessageInput::get_features () const
@@ -98,35 +103,42 @@ bool MessageInput::touch_down(int contact, int x, int y, int pressure)
98103 return false ;
99104 }
100105
106+ MouseMessageInfo move_info;
107+ if (!contact_to_mouse_move_message (contact, move_info)) {
108+ LogError << VAR (mode_) << VAR (with_cursor_pos_) << " contact out of range" << VAR (contact);
109+ return false ;
110+ }
111+
112+ MouseMessageInfo down_info;
113+ if (!contact_to_mouse_down_message (contact, down_info)) {
114+ LogError << VAR (mode_) << VAR (with_cursor_pos_) << " contact out of range" << VAR (contact);
115+ return false ;
116+ }
117+
101118 ensure_foreground ();
102119
103120 if (block_input_) {
104121 BlockInput (TRUE );
105122 }
106123
107- // 如果需要管理光标位置,保存当前位置并移动到目标位置
108124 if (with_cursor_pos_) {
109125 save_cursor_pos ();
110- set_cursor_to_client_pos (x, y);
111126 }
112127
113- // 先发送 MOVE 消息
114- touch_move (contact, x, y, pressure );
128+ // 准备位置(with_cursor_pos_ 模式下会移动光标)并发送 MOVE 消息
129+ LPARAM lParam = prepare_mouse_position ( x, y);
115130
116- std::this_thread::sleep_for (std::chrono::milliseconds (10 ));
117-
118- MouseMessageInfo msg_info;
119- if (!contact_to_mouse_down_message (contact, msg_info)) {
120- LogError << VAR (mode_) << VAR (with_cursor_pos_) << " contact out of range" << VAR (contact);
121- // 错误时恢复光标位置
131+ if (!send_or_post_w (move_info.message , move_info.w_param , lParam)) {
122132 if (with_cursor_pos_) {
123133 restore_cursor_pos ();
124134 }
125135 return false ;
126136 }
127137
128- if (!send_or_post_w (msg_info.message , msg_info.w_param , MAKELPARAM (x, y))) {
129- // 错误时恢复光标位置
138+ std::this_thread::sleep_for (std::chrono::milliseconds (10 ));
139+
140+ // 发送 DOWN 消息
141+ if (!send_or_post_w (down_info.message , down_info.w_param , lParam)) {
130142 if (with_cursor_pos_) {
131143 restore_cursor_pos ();
132144 }
@@ -149,18 +161,16 @@ bool MessageInput::touch_move(int contact, int x, int y, int pressure)
149161 return false ;
150162 }
151163
152- if (with_cursor_pos_) {
153- // 移动光标到目标位置
154- set_cursor_to_client_pos (x, y);
155- }
156-
157164 MouseMessageInfo msg_info;
158165 if (!contact_to_mouse_move_message (contact, msg_info)) {
159166 LogError << VAR (mode_) << VAR (with_cursor_pos_) << " contact out of range" << VAR (contact);
160167 return false ;
161168 }
162169
163- if (!send_or_post_w (msg_info.message , msg_info.w_param , MAKELPARAM (x, y))) {
170+ // 准备位置(with_cursor_pos_ 模式下会移动光标)并发送 MOVE 消息
171+ LPARAM lParam = prepare_mouse_position (x, y);
172+
173+ if (!send_or_post_w (msg_info.message , msg_info.w_param , lParam)) {
164174 return false ;
165175 }
166176
@@ -284,10 +294,10 @@ bool MessageInput::scroll(int dx, int dy)
284294 });
285295
286296 if (with_cursor_pos_) {
287- // 保存当前光标位置
297+ // 保存当前光标位置,并移动到上次记录的位置
288298 save_cursor_pos ();
289- // 移动光标到上次记录的位置
290- set_cursor_to_client_pos (last_pos_. first , last_pos_. second );
299+ POINT screen_pos = client_to_screen (last_pos_. first , last_pos_. second );
300+ SetCursorPos (screen_pos. x , screen_pos. y );
291301 }
292302
293303 std::this_thread::sleep_for (std::chrono::milliseconds (10 ));
0 commit comments