@@ -523,113 +523,102 @@ namespace Send::Type::Internal {
523523 std::mutex mouse_mutex;
524524
525525 public:
526- uint32_t send_mouse_input (const INPUT inputs[], uint32_t n) override {
527- uint32_t count = 0 ;
526+ bool send_mouse_input (const MOUSEINPUT& mi) override {
528527 std::lock_guard lock (mouse_mutex);
528+
529+ if constexpr (debug)
530+ DebugOStream () << L" send_mouse_input: " << mi.dwFlags << L" , " << mi.dx << L" , " << mi.dy << std::endl;
529531
530- for (uint32_t i = 0 ; i < n; i++) {
531- const MOUSEINPUT& mi = inputs[i].mi ;
532- if constexpr (debug)
533- DebugOStream () << L" send_mouse_input: " << mi.dwFlags << L" , " << mi.dx << L" , " << mi.dy << std::endl;
532+ // #TODO: move and then click, or click and then move? former?
534533
535- // #TODO: move and then click, or click and then move? former?
534+ // #TODO: MOUSEEVENTF_MOVE_NOCOALESCE, MOUSEEVENTF_VIRTUALDESK
535+ if (mi.dwFlags & MOUSEEVENTF_MOVE) {
536+ POINT move { mi.dx , mi.dy };
537+ if (mi.dwFlags & MOUSEEVENTF_ABSOLUTE) {
538+ mouse_absolute_to_screen (move);
539+ mouse_screen_to_relative (move);
540+ }
536541
537- // #TODO: MOUSEEVENTF_MOVE_NOCOALESCE, MOUSEEVENTF_VIRTUALDESK
538- if (mi.dwFlags & MOUSEEVENTF_MOVE) {
539- POINT move { mi.dx , mi.dy };
540- if (mi.dwFlags & MOUSEEVENTF_ABSOLUTE) {
541- mouse_absolute_to_screen (move);
542- mouse_screen_to_relative (move);
542+ while (abs (move.x ) > 127 || abs (move.y ) > 127 ) {
543+ if (abs (move.x ) > 127 ) {
544+ mouse_report.x = move.x > 0 ? 127 : -127 ;
545+ move.x -= mouse_report.x ;
546+ }
547+ else {
548+ mouse_report.x = 0 ;
543549 }
544550
545- while (abs (move.x ) > 127 || abs (move.y ) > 127 ) {
546- if (abs (move.x ) > 127 ) {
547- mouse_report.x = move.x > 0 ? 127 : -127 ;
548- move.x -= mouse_report.x ;
549- }
550- else {
551- mouse_report.x = 0 ;
552- }
553-
554- if (abs (move.y ) > 127 ) {
555- mouse_report.y = move.y > 0 ? 127 : -127 ;
556- move.y -= mouse_report.y ;
557- }
558- else {
559- mouse_report.y = 0 ;
560- }
561-
562- driver.report_mouse (mouse_report, compensate_switch = -compensate_switch);
551+ if (abs (move.y ) > 127 ) {
552+ mouse_report.y = move.y > 0 ? 127 : -127 ;
553+ move.y -= mouse_report.y ;
554+ }
555+ else {
556+ mouse_report.y = 0 ;
563557 }
564558
565- mouse_report.x = (uint8_t )move.x ;
566- mouse_report.y = (uint8_t )move.y ;
567- } else {
568- mouse_report.x = 0 ;
569- mouse_report.y = 0 ;
559+ driver.report_mouse (mouse_report, compensate_switch = -compensate_switch);
570560 }
571561
562+ mouse_report.x = (uint8_t )move.x ;
563+ mouse_report.y = (uint8_t )move.y ;
564+ } else {
565+ mouse_report.x = 0 ;
566+ mouse_report.y = 0 ;
567+ }
568+
572569#define CODE_GENERATE (down, up, member ) \
573- if (mi.dwFlags & down || mi.dwFlags & up) \
574- mouse_report.button .##member = mi.dwFlags & down;
570+ if (mi.dwFlags & down || mi.dwFlags & up) \
571+ mouse_report.button .##member = mi.dwFlags & down;
575572
576- CODE_GENERATE (MOUSEEVENTF_LEFTDOWN, MOUSEEVENTF_LEFTUP, LButton) // #TODO: may be switched?
577- CODE_GENERATE (MOUSEEVENTF_RIGHTDOWN, MOUSEEVENTF_RIGHTUP, RButton)
578- CODE_GENERATE (MOUSEEVENTF_MIDDLEDOWN, MOUSEEVENTF_MIDDLEUP, MButton)
573+ CODE_GENERATE (MOUSEEVENTF_LEFTDOWN, MOUSEEVENTF_LEFTUP, LButton) // #TODO: may be switched?
574+ CODE_GENERATE (MOUSEEVENTF_RIGHTDOWN, MOUSEEVENTF_RIGHTUP, RButton)
575+ CODE_GENERATE (MOUSEEVENTF_MIDDLEDOWN, MOUSEEVENTF_MIDDLEUP, MButton)
579576#undef CODE_GENERATE
580- if (mi.dwFlags & (MOUSEEVENTF_XDOWN | MOUSEEVENTF_XUP)) {
581- bool down = mi.dwFlags & MOUSEEVENTF_XDOWN;
582- switch (mi.mouseData ) {
583- case XBUTTON1: mouse_report.button .XButton1 = down; break ;
584- case XBUTTON2: mouse_report.button .XButton2 = down; break ;
585- }
577+ if (mi.dwFlags & (MOUSEEVENTF_XDOWN | MOUSEEVENTF_XUP)) {
578+ bool down = mi.dwFlags & MOUSEEVENTF_XDOWN;
579+ switch (mi.mouseData ) {
580+ case XBUTTON1: mouse_report.button .XButton1 = down; break ;
581+ case XBUTTON2: mouse_report.button .XButton2 = down; break ;
586582 }
587-
588- count += driver.report_mouse (mouse_report, compensate_switch = -compensate_switch);
589583 }
590-
591- return count ;
584+
585+ return driver. report_mouse (mouse_report, compensate_switch = -compensate_switch) ;
592586 }
593587
594588 private:
595589 LogitechDriver::KeyboardReport keyboard_report{};
596590 std::mutex keyboard_mutex;
597591 public:
598- uint32_t send_keyboard_input (const INPUT inputs[], uint32_t n) override {
599- uint32_t count = 0 ;
592+ bool send_keyboard_input (const KEYBDINPUT& ki) override {
600593 std::lock_guard lock (keyboard_mutex);
601594
602- for (uint32_t i = 0 ; i < n; i++) {
603- const KEYBDINPUT& ki = inputs[i].ki ;
604-
605- bool keydown = !(ki.dwFlags & KEYEVENTF_KEYUP);
606- if (is_modifier (ki.wVk )) {
607- set_modifier_state (ki.wVk , keydown);
608- } else {
609- uint8_t usage = driver.keyboard_vk_to_usage ((uint8_t )ki.wVk );;
610- if (keydown) {
611- for (int i = 0 ; i < 6 ; i++) {
612- if (keyboard_report.keys [i] == 0 ) {
613- keyboard_report.keys [i] = usage;
614- break ;
615- }
595+ bool keydown = !(ki.dwFlags & KEYEVENTF_KEYUP);
596+ if (is_modifier (ki.wVk )) {
597+ set_modifier_state (ki.wVk , keydown);
598+ }
599+ else {
600+ uint8_t usage = driver.keyboard_vk_to_usage ((uint8_t )ki.wVk );;
601+ if (keydown) {
602+ for (int i = 0 ; i < 6 ; i++) {
603+ if (keyboard_report.keys [i] == 0 ) {
604+ keyboard_report.keys [i] = usage;
605+ break ;
616606 }
617- // full
618607 }
619- else {
620- for (int i = 0 ; i < 6 ; i++) {
621- if (keyboard_report.keys [i] == usage) {
622- keyboard_report.keys [i] = 0 ;
623- // #TODO: move to left?
624- break ;
625- }
608+ // full
609+ }
610+ else {
611+ for (int i = 0 ; i < 6 ; i++) {
612+ if (keyboard_report.keys [i] == usage) {
613+ keyboard_report.keys [i] = 0 ;
614+ // #TODO: move to left?
615+ break ;
626616 }
627617 }
628618 }
629-
630- count += driver.report_keyboard (keyboard_report);
631619 }
632- return count;
620+
621+ return driver.report_keyboard (keyboard_report);
633622 }
634623#pragma warning(suppress : 4250) // 'class1' : inherits 'class2::member' via dominance
635624 };
0 commit comments