Cannot get SendInput () to work

I'm desperate. I have tried for several hours, but I just can't work SendInput(). Honestly, I can’t even recognize him. He always says:

Error   1   The type or namespace name 'INPUT' could not be found (are you missing a using directive or an assembly reference?)

And I just can't find out which libraries to use. There is almost zero information on what to include for this, all I can find is for C ++ or simply does not exist when I try usingit. Please, help!

I'm trying to make my mouseclick program ... Here is the code, this is one of the many versions that I found and tried to work. In this version, the program also cannot find INPUTandSendInputEventType

using System;
using System.Runtime.InteropServices;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Input;

namespace autoPlayer
{
    class Win32
    {
        enum SystemMetric
        {
          SM_CXSCREEN = 0,
          SM_CYSCREEN = 1,
        }

        [DllImport("user32.dll")]
        static extern int GetSystemMetrics(SystemMetric smIndex);

        int CalculateAbsoluteCoordinateX(int x)
        {
          return (x * 65536) / GetSystemMetrics(SystemMetric.SM_CXSCREEN);
        }

        int CalculateAbsoluteCoordinateY(int y)
        {
          return (y * 65536) / GetSystemMetrics(SystemMetric.SM_CYSCREEN);
        }

        public static void ClickLeftMouseButton(int x, int y)
        {
            INPUT mouseInput = new INPUT();
            mouseInput.type = SendInputEventType.InputMouse;
            mouseInput.mkhi.mi.dx = CalculateAbsoluteCoordinateX(x);
            mouseInput.mkhi.mi.dy = CalculateAbsoluteCoordinateY(y);
            mouseInput.mkhi.mi.mouseData = 0;


            mouseInput.mkhi.mi.dwFlags = MouseEventFlags.MOUSEEVENTF_MOVE | MouseEventFlags.MOUSEEVENTF_ABSOLUTE;
            SendInput(1, ref mouseInput, Marshal.SizeOf(new INPUT()));

            mouseInput.mkhi.mi.dwFlags = MouseEventFlags.MOUSEEVENTF_LEFTDOWN;
            SendInput(1, ref mouseInput, Marshal.SizeOf(new INPUT()));

            mouseInput.mkhi.mi.dwFlags = MouseEventFlags.MOUSEEVENTF_LEFTUP;
            SendInput(1, ref mouseInput, Marshal.SizeOf(new INPUT()));
        } 
    }
}

I would be so happy if anyone could help!

+2
2

INPUT. System.Windows.Input, , ( - using).

# VB.NET

SendInputEventType . PInvoke .

internal enum INPUT_TYPE : uint 
{
      INPUT_MOUSE = 0,
      INPUT_KEYBOARD = 1,
      INPUT_HARDWARE = 2
}

, , . .

, SendInput : , , .. winform ?

0

- :

[DllImport("user32.dll")]
   internal static extern uint SendInput (uint nInputs,
      [MarshalAs(UnmanagedType.LPArray), In] INPUT[] pInputs,
      int cbSize);
0

All Articles