Declare Function SendInput Lib "user32" (ByVal nInputs As Long, pInputs As INPUT_TYPE, ByVal cbSize As Long) As Long
В случае ошибки возвращается 0 (используйте GetLastError для получения кода ошибки). В успешном случае функция возвращает число событий, успешно добавленный в поток ввода
' Эмулируем нажатие клавиши P ' после нажатия правой кнопки мыши Dim inputevents(0 To 3) As INPUT_TYPE ' содержит информацию о каждом событии Dim keyevent As KEYBDINPUT ' события для клавиатуры Dim mouseevent As MOUSEINPUT ' события для мыши ' Загружаем информацию для эмуляции нажатий клавиши P keyevent.wVk = VK_P ' the P key keyevent.wScan = 0 ' not needed keyevent.dwFlags = 0 ' press the key down keyevent.time = 0 ' use the default keyevent.dwExtraInfo = 0 ' not needed ' Copy the structure into the input array's buffer. inputevents(0).dwType = INPUT_KEYBOARD ' keyboard input CopyMemory inputevents(0).xi(0), keyevent, Len(keyevent) ' Do the same as above, but for releasing the P key. keyevent.wVk = VK_P ' the P key keyevent.wScan = 0 ' not needed keyevent.dwFlags = KEYEVENTF_KEYUP ' release the key keyevent.time = 0 ' use the default keyevent.dwExtraInfo = 0 ' not needed inputevents(1).dwType = INPUT_KEYBOARD ' keyboard input CopyMemory inputevents(1).xi(0), keyevent, Len(keyevent) ' Load the information needed to synthesize pressing the right mouse button. mouseevent.dx = 0 ' no horizontal movement mouseevent.dy = 0 ' no vertical movement mouseevent.mouseData = 0 ' not needed mouseevent.dwFlags = MOUSEEVENTF_RIGHTDOWN ' right button down mouseevent.dwTime = 0 ' use the default mouseevent.dwExtraInfo = 0 ' not needed ' Copy the structure into the input array's buffer. inputarray(2).dwType = INPUT_MOUSE ' mouse input CopyMemory inputevents(2).xi(0), mouseevent, Len(mouseevent) ' Do the same as above, but for releasing the right mouse button. mouseevent.dx = 0 ' no horizontal movement mouseevent.dy = 0 ' no vertical movement mouseevent.mouseData = 0 ' not needed mouseevent.dwFlags = MOUSEEVENTF_RIGHTUP ' right button up mouseevent.dwTime = 0 ' use the default mouseevent.dwExtraInfo = 0 ' not needed ' Copy the structure into the input array's buffer. inputarray(3).dwType = INPUT_MOUSE ' mouse input CopyMemory inputevents(3).xi(0), mouseevent, Len(mouseevent) ' Now that all the information for the four input events has been placed ' into the array, finally send it into the input stream. SendInput(4, inputarray(0), Len(inputarray(0)) ' place the events into the stream