diff --git a/src/MaaCore/Controller/MinitouchController.cpp b/src/MaaCore/Controller/MinitouchController.cpp index b1ef5d5819..1b0d3379ae 100644 --- a/src/MaaCore/Controller/MinitouchController.cpp +++ b/src/MaaCore/Controller/MinitouchController.cpp @@ -137,7 +137,6 @@ bool asst::MinitouchController::click(const Point& p) Log.trace(m_use_maa_touch ? "maatouch" : "minitouch", "click:", p); bool ret = m_minitoucher->down(p.x, p.y) && m_minitoucher->up(); - m_minitoucher->extra_sleep(); return ret; } @@ -199,11 +198,10 @@ bool asst::MinitouchController::swipe(const Point& p1, const Point& p2, int dura minitouch_move(x1, y1, x2, y2, duration ? duration : opt.minitouch_swipe_default_duration); if (extra_swipe && opt.minitouch_extra_swipe_duration > 0) { - m_minitoucher->wait(opt.minitouch_swipe_extra_end_delay); // 停留终点 + m_minitoucher->sleep(opt.minitouch_swipe_extra_end_delay); // 停留终点 minitouch_move(x2, y2, x2, y2 - opt.minitouch_extra_swipe_dist, opt.minitouch_extra_swipe_duration); } bool ret = m_minitoucher->up(); - m_minitoucher->extra_sleep(); return ret; } diff --git a/src/MaaCore/Controller/MinitouchController.h b/src/MaaCore/Controller/MinitouchController.h index 6338a8376c..5afa5fcc2e 100644 --- a/src/MaaCore/Controller/MinitouchController.h +++ b/src/MaaCore/Controller/MinitouchController.h @@ -89,28 +89,50 @@ namespace asst bool commit() { return m_input_func(commit_cmd()); } bool down(int x, int y, int wait_ms = DefaultClickDelay, bool with_commit = true, int contact = 0) { - return m_input_func(down_cmd(x, y, wait_ms, with_commit, contact)); + if (m_input_func(down_cmd(x, y, 0, with_commit, contact))) { + sleep(wait_ms); + return true; + } + return false; } bool move(int x, int y, int wait_ms = DefaultSwipeDelay, bool with_commit = true, int contact = 0) { - return m_input_func(move_cmd(x, y, wait_ms, with_commit, contact)); + if (m_input_func(move_cmd(x, y, 0, with_commit, contact))) { + sleep(wait_ms); + return true; + } + return false; } bool up(int wait_ms = DefaultClickDelay, bool with_commit = true, int contact = 0) { - return m_input_func(up_cmd(wait_ms, with_commit, contact)); + if (m_input_func(up_cmd(0, with_commit, contact))) { + sleep(wait_ms); + return true; + } + return false; } bool key_down(int key_code, int wait_ms = DefaultClickDelay, bool with_commit = true) { - return m_input_func(key_down_cmd(key_code, wait_ms, with_commit)); + if (m_input_func(key_down_cmd(key_code, 0, with_commit))) { + sleep(wait_ms); + return true; + } + return false; } bool key_up(int key_code, int wait_ms = DefaultClickDelay, bool with_commit = true) { - return m_input_func(key_up_cmd(key_code, wait_ms, with_commit)); + if (m_input_func(key_up_cmd(key_code, 0, with_commit))) { + sleep(wait_ms); + return true; + } + return false; + } + void sleep(int ms) + { + using namespace std::chrono_literals; + std::this_thread::sleep_for(ms * 1ms); } bool wait(int ms) { return m_input_func(wait_cmd(ms)); } - void clear() noexcept { m_wait_ms_count = 0; } - - void extra_sleep() { sleep(); } private: [[nodiscard]] std::string reset_cmd() const noexcept { return "r\n"; } @@ -184,7 +206,6 @@ namespace asst [[nodiscard]] std::string wait_cmd(int ms) { - m_wait_ms_count += ms; char buff[16] = { 0 }; sprintf(buff, "w %d\n", ms); return buff; @@ -192,12 +213,6 @@ namespace asst #ifdef _MSC_VER #pragma warning(pop) #endif - void sleep() - { - using namespace std::chrono_literals; - std::this_thread::sleep_for(m_wait_ms_count * 1ms); - m_wait_ms_count = 0; - } private: Point scale(int x, int y) const noexcept @@ -229,7 +244,6 @@ namespace asst const std::function m_input_func = nullptr; const MinitouchProps& m_props; - int m_wait_ms_count = ExtraDelay; }; }; } // namespace asst