Sendinput Mouseposition WM_LBUTTONDOWN

Aug 3, 2008 at 8:57 AM
I was trying the sample from Multitouch to my application with  one panel  and inside are 9 buttons.
The application should react on  LeftButtonDown.If  Pointer is over button 1 or button 2,.. and the
LButtonDown event is fired from RAWMouse, there should be fired the Buttondown-Event from button1.


Rawinput  worked very well, i decided to take RIDEV_INPUTSINK for triggering,
for showing the RawMousePointer i have installed a small picturebox with a small imgage in it.

( If you have a better solution (DRAWIMAGE Bitmap.Maketransparent,...) please let me know. This does not
draw like a mousepointer in my solution because i do not know how to do it. I saw a solution for years ago in
Delphi with Bitblt, but i do not know now how to do it. Please could you help me)

Every time the mouse was moved, the picturebox.location.x  and picturebox.location.y was updated from me, so i can see
where the pointer is. If the pointer is over button1 and i pressed left mousebutton down, i can detect the leftbuttondown event,
but my routine does not fire the button1 down event (it seems that Sendinput is not correct working or with wrong parametes X,Y or dwflags.

What must i do to fire the event on button1 , what are the Sendinput parameters ? (dwFlags, Mousemove, Mousedown, mausabsolut, Cursor.location.X,...).
I have tryied more than 20 hours, but nothing works as it should . Please help.
Thank you very much.

Here is the routine after detecting the correct Rawmouse
private void m_MousePressed(object sender, InputDevice.MouseControlEventArgs e)
{
    if (e.Mouse.mouse_usFlags.ToString() == "0") //relative
    {
           InputDevice.Mouse_x += e.Mouse.mouse_dx;
           InputDevice.Mouse_y += e.Mouse.mouse_dy;
     }
     else
     {
           if (e.Mouse.mouse_usFlags.ToString() == "1" || e.Mouse.mouse_usFlags.ToString() == "2")  //1=absolute  2=VirtualDesktop  4=AttributChanged      never fired
          {
                  InputDevice.Mouse_x = e.Mouse.mouse_dx;
                  InputDevice.Mouse_y = e.Mouse.mouse_dy;
                  MessageBox.Show("absolute coordinates);    // never comes up, it seems that Sendinput does not send  Absolut, what is wrong with sendinput ?
          }
     }
     if (e.Mouse.mouse_ulExtraInformation != InputDevice.RAW_Mouse_Header.ToInt32())   //only when not  SENDINPUT()
    {
                if (InputDevice.Mouse_x <= 0)
                {
                    InputDevice.Mouse_x = 0;
                }
                if (InputDevice.Mouse_y <= 0)
                {
                    InputDevice.Mouse_y = 0;
                }
                if (InputDevice.Mouse_x > this.Width)
                {
                    InputDevice.Mouse_x = this.Width;
                }
                if (InputDevice.Mouse_y >= this.Height)
                {
                    InputDevice.Mouse_y = this.Height;
                }
    }

     Point pt=  PointToScreen(new Point(InputDevice.Mouse_x,InputDevice.Mouse_y));
      if (e.Mouse.mouse_usButtonFlags.ToString() == "0" &&  (e.Mouse.mouse_ulExtraInformation != InputDevice.RAW_Mouse_Header.ToInt32()))  //move Mouse, worked ok
      {
             InputDevice.MouseFrei=1;
             //Rectangle r1 = new Rectangle(Maus_x, Maus_y, bm.Width, bm.Height);
             //this.Invalidate(r1, false                 );
             //btn_Maus.Left = Maus_x;
             //btn_Maus.Top = Maus_y;
              picbox_Mouse.Left = InputDevice.Mouse_x;
              picbox_Mouse.Top = InputDevice.Mouse_y;
              picbox_Mouse.BringToFront();
              return;
       }               
       if (e.Mouse.mouse_usButtonFlags.ToString() == "1") // Mousedown left Button
       {
                InputDevice.MouseFrei=0;  //block  input in prefiltermessage(true) procedure
                if (e.Mouse.mouse_ulExtraInformation == InputDevice.RAW_Mouse_Header.ToInt32())  //only when from Sendinput(), not from normal press, because of the orginial mousepointer location
                {
                    InputDevice.MouseFrei = 1;   // input ok,  prefiltermessage(false)
                    Cursor.Position = pt;

                    InputDevice.INPUT[] input1 = new InputDevice.INPUT[1];
                    input1[0].type = 0; // Mouse=0
                    input1[0].mi.dwExtraInfo = InputDevice.RAW_Mouse_Header.ToInt32();
                    input1[0].mi.dx = pt.X;     // is the location false ?, must there only  picbox_Mouse.X  or perhaps PointToClient(picbox_Mouse.X, picbox-Mouse.Y)
                    input1[0].mi.dy = pt.Y;
                    input1[0].mi.dwFlags = InputDevice.MOUSEEVENTF_LEFTDOWN  |  InputDevice.MOUSEEVENTF_ABSOLUTE;   //must i send MOUSEEVENT_MOVE ?

                    InputDevice.SendInput((uint)input1.Length, input1, Marshal.SizeOf(input1[0]));         //must i send 2 times Sendinput, for every flag,

                }
                return
       }
}



Aug 3, 2008 at 9:05 AM
I forgot to show you the Code  under the following lines:

 input1[0].mi.dwFlags = InputDevice.MOUSEEVENTF_LEFTDOWN  |  InputDevice.MOUSEEVENTF_ABSOLUTE;   //must i send MOUSEEVENT_MOVE ?
 InputDevice.SendInput((uint)input1.Length, input1, Marshal.SizeOf(input1[0]));         //must i send 2 times Sendinput, for every flag,
 }



InputDevice.MouseFrei = 0;
InputDevice.INPUT[] input = new InputDevice.INPUT[1];
input[0].type = 0; // Mouse=0
input[0].mi.dwExtraInfo = InputDevice.RAW_Mouse_Header.ToInt32();
input[0].mi.dx = pic_Maus.Location.X;
input[0].mi.dy = pic_Maus.Location.Y;
input[0].mi.dwFlags = InputDevice.MOUSEEVENTF_LEFTDOWN | InputDevice.MOUSEEVENTF_ABSOLUTE | InputDevice.MOUSEEVENTF_MOVE;
InputDevice.SendInput((uint)input.Length, input, Marshal.SizeOf(input[0]));

return;

Coordinator
Aug 4, 2008 at 9:30 AM
Edited Aug 4, 2008 at 9:34 AM
Are you saying that your picturebox gets event but button under it not? If yes then you have to override CreateParams method in you cursor form like this:

  protected override CreateParams CreateParams
  {
   get
   {
    CreateParams cp = base.CreateParams;
    WindowExStyleFlags f = (WindowExStyleFlags)134742176;
    f = f | WindowExStyleFlags.TOPMOST;
    cp.ExStyle = (cp.ExStyle | (int)f);
    return cp;
   }
  }

   TOPMOST = 0x00000008

Just look at files: DebugCursor.cs, DeviceStatus.cs and RawDevicesManager.cs in MultiTouchVista project at "Main Source\InputProviders\MultipleMice\".
There is everything you need.