How does the sendInput () function work in C #?

I am doing a project using key stimulation, and I use two ways to display a key symbol on the screen. At first I use the clipboard, but using the clipboard is sometimes inconvenient, so I try to use SendInput () to display the key character when the user presses any button on the keyboard. I am following a tutorial, but I did not know how the SendInput () function works (I mean, when I call SendInput (), what will it work step by step?). Does anyone have experience in my case? Please explain me. Thanks everyone!

private void SendUnicode(string _text)
    {
        if (IntPtr.Size == 4)
        {
            ViKey.INPUT[] input = new ViKey.INPUT[_text.Length * 2];
            for (int i = 0; i < _text.Length; i++)
            {
                input[i * 2].type = 1;
                input[i * 2].ki.wVk = 0;
                input[i * 2].ki.wScan = (short)_text[i];
                input[i * 2].ki.dwFlags = 4;
                input[i * 2 + 1] = input[i * 2];
                input[i * 2 + 1].ki.dwFlags = 6;
            }
            ViKey.SendInput((uint)input.Length, input, Marshal.SizeOf(input[0]));
            return;
        }
        else
        {
            ViKey.INPUT64[] inputx64 = new ViKey.INPUT64[_text.Length * 2];
            for (int i = 0; i < _text.Length; i++)
            {
                inputx64[i * 2].type = 1;
                inputx64[i * 2].ki.wVk = 0;
                inputx64[i * 2].ki.wScan = (short)_text[i];
                inputx64[i * 2].ki.dwFlags = 4;
                inputx64[i * 2 + 1] = inputx64[i * 2];
                inputx64[i * 2 + 1].ki.dwFlags = 6;
            }
            ViKey.SendInput((uint)inputx64.Length, inputx64, Marshal.SizeOf(inputx64[0]));
        }
    }
-5
source share
1 answer

All relevant information is contained in the function documentation.

. , .

, , , INPUT ( ) , , .

0

All Articles