Skip to content

Instantly share code, notes, and snippets.

@fanux365
Last active June 1, 2018 14:56
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save fanux365/3f4b812fbf8bacd5192c244c83f10705 to your computer and use it in GitHub Desktop.
Save fanux365/3f4b812fbf8bacd5192c244c83f10705 to your computer and use it in GitHub Desktop.
#include "stdafx.h"
#include <windows.h>
#include <iostream>
#include <string>
#include <iostream>
#include <string>
#include <time.h>
#include <stdlib.h>
using namespace std;
string random(int len)
{
string a = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789";
string r;
srand(time(NULL));
for (int i = 0; i < len; i++) r.push_back(a.at(size_t(rand() % 62)));
return r;
}
void SetClipboard(char *output)
{
const size_t len = strlen(output) + 1;
HGLOBAL hMem = GlobalAlloc(GMEM_MOVEABLE, len);
memcpy(GlobalLock(hMem), output, len);
GlobalUnlock(hMem);
OpenClipboard(0);
EmptyClipboard();
SetClipboardData(CF_TEXT, hMem);
CloseClipboard();
}
int _cdecl _tmain(
int argc,
TCHAR *argv[])
{
char * buffer;
if (RegisterHotKey(
NULL,
1,
MOD_NOREPEAT,
0x70)) //0x42 is 'b'
{
_tprintf(_T("Hotkey 'ALT+b' registered, using MOD_NOREPEAT flag\n"));
}
MSG msg = { 0 };
while (GetMessage(&msg, NULL, 0, 0) != 0)
{
if (msg.message == WM_HOTKEY)
{
// Onpress
char * buffer;
if (OpenClipboard(NULL))
{
buffer = (char*)GetClipboardData(CF_TEXT);
//do something with buffer here
//before it goes out of scope
std::cout << strlen(buffer);
std::cout << random(strlen(buffer));
_tprintf(_T("Randomed\n"));
SetClipboard(&random(strlen(buffer))[0u]);
_tprintf(_T("Coppied\n"));
}
}
}
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment