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
  1. Home
  2. General Programming
  3. C / C++ / MFC
  4. Unable to control mouse events

Unable to control mouse events

Scheduled Pinned Locked Moved C / C++ / MFC
hardwarehelpdiscussion
7 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.
  • A Offline
    A Offline
    AprNgp
    wrote on last edited by
    #1

    I am attempting to control mouse events, like moving the mouse and pressing any mouse key ... I am using the following code to set the mouse position as (0,0)

    LPINPUT i;
    MOUSEINPUT mi;
    mi.dx=0;
    mi.dy=0;
    mi.dwFlags=MOUSEEVENTF_LEFTDOWN;
    mi.time=0;
    mi.dwExtraInfo=GetMessageExtraInfo();
    mi.mouseData=0;
    i[0].mi=mi;
    i[0].type=INPUT_MOUSE;
    SendInput(1,i,sizeof(i));

    But, I am getting an exception at the line i[0].mi=mi; Actually I want to control the mouse pointer through an external hardware, which will be connected at the serial port. I will read the data from the serial port like mouse movement and any mouse key being pressed, then SET this mouse status to the system mouse ....this is my ultimate aim ... So I wrote the above code to set the mouse position first, but its not working ... Please someone help me here ...

    Apurv A man is but the product of his thoughts. What he thinks, he becomes. .......Mahatma Gandhi Be the change you want to see in the world. .......Mahatma Gandhi

    A 1 Reply Last reply
    0
    • A AprNgp

      I am attempting to control mouse events, like moving the mouse and pressing any mouse key ... I am using the following code to set the mouse position as (0,0)

      LPINPUT i;
      MOUSEINPUT mi;
      mi.dx=0;
      mi.dy=0;
      mi.dwFlags=MOUSEEVENTF_LEFTDOWN;
      mi.time=0;
      mi.dwExtraInfo=GetMessageExtraInfo();
      mi.mouseData=0;
      i[0].mi=mi;
      i[0].type=INPUT_MOUSE;
      SendInput(1,i,sizeof(i));

      But, I am getting an exception at the line i[0].mi=mi; Actually I want to control the mouse pointer through an external hardware, which will be connected at the serial port. I will read the data from the serial port like mouse movement and any mouse key being pressed, then SET this mouse status to the system mouse ....this is my ultimate aim ... So I wrote the above code to set the mouse position first, but its not working ... Please someone help me here ...

      Apurv A man is but the product of his thoughts. What he thinks, he becomes. .......Mahatma Gandhi Be the change you want to see in the world. .......Mahatma Gandhi

      A Offline
      A Offline
      Akt_4_U
      wrote on last edited by
      #2

      LPINPUT i; LPINPUT means pointer to structure INPUT. Here i is of type LPINPUT. You have to allocate memory for this before you use this variable. ie LPINPUT i = new INPUT;

      akt

      A 1 Reply Last reply
      0
      • A Akt_4_U

        LPINPUT i; LPINPUT means pointer to structure INPUT. Here i is of type LPINPUT. You have to allocate memory for this before you use this variable. ie LPINPUT i = new INPUT;

        akt

        A Offline
        A Offline
        AprNgp
        wrote on last edited by
        #3

        oh ... thanks ... its not giving anymore errors ... but the mouse position is not set .... here is my updated code ...

        LPINPUT i = new INPUT;
        MOUSEINPUT mi;
        mi.dx=0;
        mi.dy=0;
        mi.dwFlags=MOUSEEVENTF_MOVE;
        mi.time=0;
        mi.dwExtraInfo=GetMessageExtraInfo();
        mi.mouseData=0;
        i[0].mi=mi;
        i[0].type=INPUT_MOUSE;
        SendInput(1,i,sizeof(i));

        Apurv A man is but the product of his thoughts. What he thinks, he becomes. .......Mahatma Gandhi Be the change you want to see in the world. .......Mahatma Gandhi

        _ A 2 Replies Last reply
        0
        • A AprNgp

          oh ... thanks ... its not giving anymore errors ... but the mouse position is not set .... here is my updated code ...

          LPINPUT i = new INPUT;
          MOUSEINPUT mi;
          mi.dx=0;
          mi.dy=0;
          mi.dwFlags=MOUSEEVENTF_MOVE;
          mi.time=0;
          mi.dwExtraInfo=GetMessageExtraInfo();
          mi.mouseData=0;
          i[0].mi=mi;
          i[0].type=INPUT_MOUSE;
          SendInput(1,i,sizeof(i));

          Apurv A man is but the product of his thoughts. What he thinks, he becomes. .......Mahatma Gandhi Be the change you want to see in the world. .......Mahatma Gandhi

          _ Offline
          _ Offline
          _Superman_
          wrote on last edited by
          #4

          Try this

          INPUT i;
          MOUSEINPUT mi;
          mi.dx=0;
          mi.dy=0;
          mi.dwFlags=MOUSEEVENTF_MOVE;
          mi.time=0;
          mi.dwExtraInfo=GetMessageExtraInfo();
          mi.mouseData=0;
          i.mi=mi;
          i.type=INPUT_MOUSE;
          SendInput(1, &i, sizeof(i));

          «_Superman_» I love work. It gives me something to do between weekends.

          A 1 Reply Last reply
          0
          • A AprNgp

            oh ... thanks ... its not giving anymore errors ... but the mouse position is not set .... here is my updated code ...

            LPINPUT i = new INPUT;
            MOUSEINPUT mi;
            mi.dx=0;
            mi.dy=0;
            mi.dwFlags=MOUSEEVENTF_MOVE;
            mi.time=0;
            mi.dwExtraInfo=GetMessageExtraInfo();
            mi.mouseData=0;
            i[0].mi=mi;
            i[0].type=INPUT_MOUSE;
            SendInput(1,i,sizeof(i));

            Apurv A man is but the product of his thoughts. What he thinks, he becomes. .......Mahatma Gandhi Be the change you want to see in the world. .......Mahatma Gandhi

            A Offline
            A Offline
            Akt_4_U
            wrote on last edited by
            #5

            Please check the last parameter of SendInput(); It requires the size of structure INPUT. For this you have call sizeof(INPUT). In your code, you have taken sizeof(i). i means LPINPUT. As i said earlier LPINPUT is a pointer. So sizeof(i) will return the size of a pointer variable only(4 bytes).

            akt

            1 Reply Last reply
            0
            • _ _Superman_

              Try this

              INPUT i;
              MOUSEINPUT mi;
              mi.dx=0;
              mi.dy=0;
              mi.dwFlags=MOUSEEVENTF_MOVE;
              mi.time=0;
              mi.dwExtraInfo=GetMessageExtraInfo();
              mi.mouseData=0;
              i.mi=mi;
              i.type=INPUT_MOUSE;
              SendInput(1, &i, sizeof(i));

              «_Superman_» I love work. It gives me something to do between weekends.

              A Offline
              A Offline
              AprNgp
              wrote on last edited by
              #6

              its working ... superman .... thank you very much .... will this SendInput() function work outside the application window ? I mean, while i interface it with my hardware, so that the key inputs are coming from the hardware, know suppose the mouse is over the start button, and i send the Left-button pressed event to the SendInput() function ... will this result the Start button being pressed ???

              Apurv A man is but the product of his thoughts. What he thinks, he becomes. .......Mahatma Gandhi Be the change you want to see in the world. .......Mahatma Gandhi

              _ 1 Reply Last reply
              0
              • A AprNgp

                its working ... superman .... thank you very much .... will this SendInput() function work outside the application window ? I mean, while i interface it with my hardware, so that the key inputs are coming from the hardware, know suppose the mouse is over the start button, and i send the Left-button pressed event to the SendInput() function ... will this result the Start button being pressed ???

                Apurv A man is but the product of his thoughts. What he thinks, he becomes. .......Mahatma Gandhi Be the change you want to see in the world. .......Mahatma Gandhi

                _ Offline
                _ Offline
                _Superman_
                wrote on last edited by
                #7

                I believe that it will work where ever the mouse pointer is located.

                «_Superman_» I love work. It gives me something to do between weekends.

                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