Dec 21, 2018 at 10:08pm UTC
this is basically supposed to read the text file and copy the contents and paste them into the program that's currently active line by line
#include <iostream>
#include <fstream>
#define WINVER 0x0500
#include <windows.h>
using namespace std;
INPUT ctrl;
INPUT v;
void toClipboard(const string &s)
{
OpenClipboard(0);
EmptyClipboard();
HGLOBAL hg = GlobalAlloc(GMEM_MOVEABLE,s.size());
if (!hg)
{
CloseClipboard();
return;
}
memcpy(GlobalLock(hg), s.c_str(),s.size());
GlobalUnlock(hg);
SetClipboardData(CF_TEXT,hg);
CloseClipboard();
GlobalFree(hg);
}
int main()
{
ifstream generatorInput("file.txt");
string line;
while (getline(generatorInput, line))
{
toClipboard(line);
Sleep(1000); //using this for testing purposes - gives me one second to open notepad so i can see if it actually works or not
//this stuff might be a little weird and over-complicated since i was in a hurry and most of this is not even mine anyways lol
ctrl.type = INPUT_KEYBOARD;
ctrl.ki.wScan = 0;
ctrl.ki.time = 0;
ctrl.ki.dwExtraInfo = 0;
v.type = INPUT_KEYBOARD;
v.ki.wScan = 0;
v.ki.time = 0;
v.ki.dwExtraInfo = 0;
ctrl.ki.wVk = 0x11;
ctrl.ki.dwFlags = 0;
SendInput(1, &ctrl, sizeof(INPUT));
v.ki.wVk = 0x56;
v.ki.dwFlags = 0;
SendInput(1, &v, sizeof(INPUT));
ctrl.ki.dwFlags = KEYEVENTF_KEYUP;
SendInput(1, &ctrl, sizeof(INPUT));
v.ki.dwFlags = KEYEVENTF_KEYUP;
SendInput(1, &v, sizeof(INPUT));
}
}
basically, the issue is that it copies the first line, it won't ever go further than the first line
kinda new to c++ so excuse my lack of knowledge, if there's anything i could've done better, let me know
thanks! (the code format thing didn't work either, new to this forum, sorry!)
Last edited on Dec 21, 2018 at 10:09pm UTC
Dec 22, 2018 at 8:04am UTC
Try reading the complete file into a string and copy the whole string to the clipboard.
What's the purpose of these SendInput ?