Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
CODE PROJECT For Those Who Code
  • Home
  • Articles
  • FAQ
Community
  1. Home
  2. General Programming
  3. C / C++ / MFC
  4. SendInput() and MOUSEINPUT Problems

SendInput() and MOUSEINPUT Problems

Scheduled Pinned Locked Moved C / C++ / MFC
questionhelp
8 Posts 3 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • M Offline
    M Offline
    Madhu_Rani
    wrote on last edited by
    #1

    INPUT myInput; myInput.type = INPUT_MOUSE; MOUSEINPUT mouseInput; mouseInput.dwFlags = MOUSEEVENTF_MOVE|MOUSEEVENTF_ABSOLUTE; mouseInput.dx = 0; mouseInput.dy = 690; mouseInput.mouseData = 0; mouseInput.time = 0; mouseInput.dwExtraInfo = NULL; myInput.mi = mouseInput; SendInput(1, &myInput, sizeof(INPUT)); PROBLEM 1: The mouse is moved at the upper-left corner while through this code, I am requesting :laugh: him to move to BOTTOM-LEFT corner? Why this is not happening. PROBLEM 2: I want to send event MOUSEEVENTF_RIGHTDOWN ( right button pressed at BOTTOM-LEFT), and request the system that please feel like as I click you at start button :( , but it is not accepting my command, I changed the flag to mouseInput.dwFlags=MOUSEEVENTF_RIGHTDOWN|MOUSEEVENTF_ABSOLUTE; So What is wrong ?

    A D 2 Replies Last reply
    0
    • M Madhu_Rani

      INPUT myInput; myInput.type = INPUT_MOUSE; MOUSEINPUT mouseInput; mouseInput.dwFlags = MOUSEEVENTF_MOVE|MOUSEEVENTF_ABSOLUTE; mouseInput.dx = 0; mouseInput.dy = 690; mouseInput.mouseData = 0; mouseInput.time = 0; mouseInput.dwExtraInfo = NULL; myInput.mi = mouseInput; SendInput(1, &myInput, sizeof(INPUT)); PROBLEM 1: The mouse is moved at the upper-left corner while through this code, I am requesting :laugh: him to move to BOTTOM-LEFT corner? Why this is not happening. PROBLEM 2: I want to send event MOUSEEVENTF_RIGHTDOWN ( right button pressed at BOTTOM-LEFT), and request the system that please feel like as I click you at start button :( , but it is not accepting my command, I changed the flag to mouseInput.dwFlags=MOUSEEVENTF_RIGHTDOWN|MOUSEEVENTF_ABSOLUTE; So What is wrong ?

      A Offline
      A Offline
      Adam Roderick J
      wrote on last edited by
      #2

      did u called SetCursorPos to set the cursor to that possition before sending the mouse input?

      Величие не Бога может быть недооценена.

      M 1 Reply Last reply
      0
      • A Adam Roderick J

        did u called SetCursorPos to set the cursor to that possition before sending the mouse input?

        Величие не Бога может быть недооценена.

        M Offline
        M Offline
        Madhu_Rani
        wrote on last edited by
        #3

        VOW you are GENIOUS. THANKS. Now I also find the solution of problem2 that I pasted below. Actually in none of the article that are related with the SendInput , anyone talked about SetCursorPos. I guess it is good to call SetCursorPos first and then use the SendInput() function. 1- First Call SetCurPos() 2- then Call the SendInput() to perform the mouse events like button down up etc. INPUT rightClick[2]; MOUSEINPUT rightDown; rightDown.dwFlags = MOUSEEVENTF_RIGHTDOWN + MOUSEEVENTF_ABSOLUTE; rightDown.dx = 0; rightDown.dy = 0; rightDown.time = 0; rightDown.mouseData = 0; MOUSEINPUT rightUp; rightUp.dwFlags = MOUSEEVENTF_RIGHTUP + MOUSEEVENTF_ABSOLUTE; rightUp.dx = 0; rightUp.dy = 0; rightUp.time = 0; rightUp.mouseData = 0; rightClick[0].type = INPUT_MOUSE; rightClick[0].mi = rightDown; rightClick[1].type = INPUT_MOUSE; rightClick[1].mi = rightUp; // finally, send the spoofed right-click to invoke the menu ::SendInput( 2, rightClick, sizeof(rightClick[0]));

        M 1 Reply Last reply
        0
        • M Madhu_Rani

          VOW you are GENIOUS. THANKS. Now I also find the solution of problem2 that I pasted below. Actually in none of the article that are related with the SendInput , anyone talked about SetCursorPos. I guess it is good to call SetCursorPos first and then use the SendInput() function. 1- First Call SetCurPos() 2- then Call the SendInput() to perform the mouse events like button down up etc. INPUT rightClick[2]; MOUSEINPUT rightDown; rightDown.dwFlags = MOUSEEVENTF_RIGHTDOWN + MOUSEEVENTF_ABSOLUTE; rightDown.dx = 0; rightDown.dy = 0; rightDown.time = 0; rightDown.mouseData = 0; MOUSEINPUT rightUp; rightUp.dwFlags = MOUSEEVENTF_RIGHTUP + MOUSEEVENTF_ABSOLUTE; rightUp.dx = 0; rightUp.dy = 0; rightUp.time = 0; rightUp.mouseData = 0; rightClick[0].type = INPUT_MOUSE; rightClick[0].mi = rightDown; rightClick[1].type = INPUT_MOUSE; rightClick[1].mi = rightUp; // finally, send the spoofed right-click to invoke the menu ::SendInput( 2, rightClick, sizeof(rightClick[0]));

          M Offline
          M Offline
          Madhu_Rani
          wrote on last edited by
          #4

          Another Problem: The logic of SetCurPos()works for the right clicks and OS take the appropriate action against the right click, but it did not work for left click. When I changed both flags to MOUSEEVENTF_ LEFTDOWN in the code. The cursor goes at the bottom-left corner but application can not trigger the start button (Window Start) event, as cursor was at that point. Actually if the cursor is at the button, then we require to have a left click at button? so how we manage a click at a button by using sendinput() method. SetCursorPos(10,790); INPUT rightClick[2]; MOUSEINPUT rightDown; rightDown.dwFlags = MOUSEEVENTF_RIGHTDOWN + MOUSEEVENTF_ABSOLUTE; rightDown.dx = 0; rightDown.dy = 0; rightDown.time = 0; rightDown.mouseData = 0; MOUSEINPUT rightUp; rightUp.dwFlags = MOUSEEVENTF_RIGHTUP + MOUSEEVENTF_ABSOLUTE; rightUp.dx = 0; rightUp.dy = 0; rightUp.time = 0; rightUp.mouseData = 0; rightClick[0].type = INPUT_MOUSE; rightClick[0].mi = rightDown; rightClick[1].type = INPUT_MOUSE; rightClick[1].mi = rightUp; // finally, send the spoofed right-click to invoke the menu ::SendInput( 2, rightClick, sizeof(rightClick[0]));

          A 1 Reply Last reply
          0
          • M Madhu_Rani

            Another Problem: The logic of SetCurPos()works for the right clicks and OS take the appropriate action against the right click, but it did not work for left click. When I changed both flags to MOUSEEVENTF_ LEFTDOWN in the code. The cursor goes at the bottom-left corner but application can not trigger the start button (Window Start) event, as cursor was at that point. Actually if the cursor is at the button, then we require to have a left click at button? so how we manage a click at a button by using sendinput() method. SetCursorPos(10,790); INPUT rightClick[2]; MOUSEINPUT rightDown; rightDown.dwFlags = MOUSEEVENTF_RIGHTDOWN + MOUSEEVENTF_ABSOLUTE; rightDown.dx = 0; rightDown.dy = 0; rightDown.time = 0; rightDown.mouseData = 0; MOUSEINPUT rightUp; rightUp.dwFlags = MOUSEEVENTF_RIGHTUP + MOUSEEVENTF_ABSOLUTE; rightUp.dx = 0; rightUp.dy = 0; rightUp.time = 0; rightUp.mouseData = 0; rightClick[0].type = INPUT_MOUSE; rightClick[0].mi = rightDown; rightClick[1].type = INPUT_MOUSE; rightClick[1].mi = rightUp; // finally, send the spoofed right-click to invoke the menu ::SendInput( 2, rightClick, sizeof(rightClick[0]));

            A Offline
            A Offline
            Adam Roderick J
            wrote on last edited by
            #5

            void GenerateKey(int vk , BOOL bExtended) { KEYBDINPUT kb = {0}; INPUT Input = {0}; // generate down if(bExtended) kb.dwFlags = KEYEVENTF_EXTENDEDKEY; kb.wVk = vk; Input.type = INPUT_KEYBOARD; Input.ki = kb; ::SendInput(1, &Input, sizeof(Input)); // generate up ::ZeroMemory(&kb, sizeof(KEYBDINPUT)); ::ZeroMemory(&Input, sizeof(INPUT)); kb.dwFlags = KEYEVENTF_KEYUP; if(bExtended) kb.dwFlags |= KEYEVENTF_EXTENDEDKEY; kb.wVk = vk; Input.type = INPUT_KEYBOARD; Input.ki = kb; ::SendInput(1, &Input, sizeof(Input)); } check this

            Величие не Бога может быть недооценена.

            M 1 Reply Last reply
            0
            • A Adam Roderick J

              void GenerateKey(int vk , BOOL bExtended) { KEYBDINPUT kb = {0}; INPUT Input = {0}; // generate down if(bExtended) kb.dwFlags = KEYEVENTF_EXTENDEDKEY; kb.wVk = vk; Input.type = INPUT_KEYBOARD; Input.ki = kb; ::SendInput(1, &Input, sizeof(Input)); // generate up ::ZeroMemory(&kb, sizeof(KEYBDINPUT)); ::ZeroMemory(&Input, sizeof(INPUT)); kb.dwFlags = KEYEVENTF_KEYUP; if(bExtended) kb.dwFlags |= KEYEVENTF_EXTENDEDKEY; kb.wVk = vk; Input.type = INPUT_KEYBOARD; Input.ki = kb; ::SendInput(1, &Input, sizeof(Input)); } check this

              Величие не Бога может быть недооценена.

              M Offline
              M Offline
              Madhu_Rani
              wrote on last edited by
              #6

              Thanks. Though it is not a recomended method but I called the SendInput function twice and now it works:) ::SendInput( 2, leftClick, sizeof(leftClick[0])); ::SendInput( 2, leftClick, sizeof(leftClick[0]));

              A 1 Reply Last reply
              0
              • M Madhu_Rani

                Thanks. Though it is not a recomended method but I called the SendInput function twice and now it works:) ::SendInput( 2, leftClick, sizeof(leftClick[0])); ::SendInput( 2, leftClick, sizeof(leftClick[0]));

                A Offline
                A Offline
                Adam Roderick J
                wrote on last edited by
                #7

                good, Just check by chaning the Time stamp for the event.

                Величие не Бога может быть недооценена.

                1 Reply Last reply
                0
                • M Madhu_Rani

                  INPUT myInput; myInput.type = INPUT_MOUSE; MOUSEINPUT mouseInput; mouseInput.dwFlags = MOUSEEVENTF_MOVE|MOUSEEVENTF_ABSOLUTE; mouseInput.dx = 0; mouseInput.dy = 690; mouseInput.mouseData = 0; mouseInput.time = 0; mouseInput.dwExtraInfo = NULL; myInput.mi = mouseInput; SendInput(1, &myInput, sizeof(INPUT)); PROBLEM 1: The mouse is moved at the upper-left corner while through this code, I am requesting :laugh: him to move to BOTTOM-LEFT corner? Why this is not happening. PROBLEM 2: I want to send event MOUSEEVENTF_RIGHTDOWN ( right button pressed at BOTTOM-LEFT), and request the system that please feel like as I click you at start button :( , but it is not accepting my command, I changed the flag to mouseInput.dwFlags=MOUSEEVENTF_RIGHTDOWN|MOUSEEVENTF_ABSOLUTE; So What is wrong ?

                  D Offline
                  D Offline
                  David Crow
                  wrote on last edited by
                  #8

                  I think the operative word is normalized. Notice the range for dx and dy is from 0 to 65535, regardless of monitor resolution. The MOUSEINPUT structure is not necessary as the INPUT structure already has one, like:

                  INPUT myInput;
                  myInput.type = INPUT_MOUSE;
                  myInput.mi.dwFlags = MOUSEEVENTF_MOVE | MOUSEEVENTF_ABSOLUTE;
                  myInput.mi.dx = 0;
                  myInput.mi.dy = 690;
                  myInput.mi.mouseData = 0;
                  myInput.mi.time = 0;
                  myInput.mi.dwExtraInfo = NULL;

                  "Old age is like a bank account. You withdraw later in life what you have deposited along the way." - Unknown

                  "Fireproof doesn't mean the fire will never come. It means when the fire comes that you will be able to withstand it." - Michael Simmons

                  1 Reply Last reply
                  0
                  Reply
                  • Reply as topic
                  Log in to reply
                  • Oldest to Newest
                  • Newest to Oldest
                  • Most Votes


                  • Login

                  • Don't have an account? Register

                  • Login or register to search.
                  • First post
                    Last post
                  0
                  • Categories
                  • Recent
                  • Tags
                  • Popular
                  • World
                  • Users
                  • Groups