I am trying to make a discord autodelete script with SendInput but there is a problem when I run the script twice, the first time it all good than in the other it dosent respond properly.
this function is on the delete of massage- its supposed to be up, ctrl a, backspace, enter and enter.
static bool DelDiscordMsg()
{
INPUT inputs[9] = {};
ZeroMemory(inputs, sizeof(inputs));
inputs[0].type = INPUT_KEYBOARD;
inputs[0].ki.wVk = VK_UP;
inputs[1].type = INPUT_KEYBOARD;
inputs[1].ki.wVk = VK_UP;
inputs[1].ki.dwFlags = KEYEVENTF_KEYUP;
inputs[2].type = INPUT_KEYBOARD;
inputs[2].ki.wVk = VK_CONTROL;
inputs[3].type = INPUT_KEYBOARD;
inputs[3].ki.wVk = 'A';
inputs[4].type = INPUT_KEYBOARD;
inputs[4].ki.wVk = VK_CONTROL;
inputs[4].ki.dwFlags = KEYEVENTF_KEYUP;
inputs[5].type = INPUT_KEYBOARD;
inputs[5].ki.wVk = VK_BACK;
inputs[6].type = INPUT_KEYBOARD;
inputs[6].ki.wVk = VK_RETURN;
inputs[7].type = INPUT_KEYBOARD;
inputs[7].ki.wVk = VK_RETURN;
inputs[8].type = INPUT_KEYBOARD;
inputs[8].ki.wVk = VK_RETURN;
UINT uSent = SendInput(ARRAYSIZE(inputs), inputs, sizeof(INPUT));
if (uSent != ARRAYSIZE(inputs))
{
return false;
}
return true;
}
static bool NextMsg()
{
INPUT inputs[4] = {};
ZeroMemory(inputs, sizeof(inputs));
Sleep(300);
inputs[0].type = INPUT_KEYBOARD;
inputs[0].ki.wVk = VK_RETURN;
inputs[1].type = INPUT_KEYBOARD;
inputs[1].ki.wVk = VK_BACK;
Sleep(300);
inputs[2].type = INPUT_KEYBOARD;
inputs[2].ki.wVk = VK_UP;
Sleep(300);
inputs[3].type = INPUT_KEYBOARD;
inputs[3].ki.wVk = VK_UP;
inputs[3].ki.dwFlags = KEYEVENTF_KEYUP;
UINT uSent = SendInput(ARRAYSIZE(inputs), inputs, sizeof(INPUT));
if (uSent != ARRAYSIZE(inputs))
{
return false;
}
return true;
}
this function is to get to the massage every time it does DelDiscordMsg.
Main:
int main()
{
std::this_thread::sleep_for(std::chrono::seconds(3));
bool flag = true;
NextMsg();
for (size_t i = 0; i < 5; i++)
{
Sleep(500);
flag=DelDiscordMsg();
if (flag==false)
{
break;
}
Sleep(500);
NextMsg();
}
}
New contributor
GOBI is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.