0

Is it possible to use C++ to simulate keypress? What I mean by that I mean is it possible to use C++ to emulate your keyboard to type out a word. If you are still confused about what I am talking about (Like the rest of the internet) then what I am trying to say is if there is a way to copy something like pyautogui and pynput in C++. I've looked everywhere for an answer but all I saw was key detection. I want to know how to do this because my friends keep spamming me so I want to get my revenge by making a spam bot. Here's the code so far..

#include <iostream>
#include <windows.h>

using namespace std;

string message = "Lol";
float delay = 0.2f;

void click_to_location()
{
    Sleep(5000);
    SetCursorPos(525, 665);
    Sleep(10);
    mouse_event(MOUSEEVENTF_LEFTDOWN, 0, 0, 0, 0);
    mouse_event(MOUSEEVENTF_LEFTUP, 0, 0, 0, 0);
    Sleep(10);
}

int main()
{
    while (true)
    {
        if (GetAsyncKeyState(0x51))
        {
            exit(0);
        }
        // Help with key Press here
        Sleep(10);
        // Help with key Release here
    }

    return 0;
}

Also ignore my bad programming skills.

NoobBit
  • 1
  • 1
  • 2
  • If you're looking for solutions for Windows, check [SendInput() not equal to pressing key manually on keyboard in C++?](https://stackoverflow.com/a/18854441/9404007), change the scan code to whatever you want – Tomingsun Oct 27 '21 at 05:19

1 Answers1

0

From my experience, simulate keystroke is not language specific.

Can simulate keystroke on windows using win32 api and c++. https://learn.microsoft.com/en-us/windows/win32/learnwin32/keyboard-input

kenash0625
  • 657
  • 3
  • 8