Ik heb deze code:
Het is de bedoeling dat hij de openstaande kladblok naar voorgrond zet en om de 10 seconden zegt dat C wordt ingedrukt..
Hij vindt de windows en zegt dat "C pressed." maar er verschijnt geen c in notepad..
Weet iemand wat ik fout doe?
Code:
#define _WIN32_WINNT 0x0501
#include <windows.h>
#include <iostream>
#define VK_C 43
using std::cin;
using std::cout;
void TellKeyPress(int);
int main()
{
cout << "Press a key to start.";
cin.get();
HWND hWndNotepad = FindWindow(NULL, "Naamloos - Kladblok"); //Find notepad
if(hWndNotepad== NULL){ cout << "Could not find Notepad.\n"; cin.get(); return 0;}
HWND hWndEdit = GetWindow(hWndNotepad, GW_CHILD); //Get edit window
if(hWndEdit == NULL){ cout << "Could not find child window.\n"; cin.get(); return 0;}
SetForegroundWindow(hWndEdit);
while(1)
{
TellKeyPress(VK_C);
cout << "C Pressed.\n";
Sleep(10000);
}
return 0;
}
void TellKeyPress(int iKey)
{
INPUT* key;
key = new INPUT;
key->type = INPUT_KEYBOARD;
key->ki.wVk = iKey;
key->ki.dwFlags = 0;
key->ki.time = 0;
key->ki.wScan = 0;
key->ki.dwExtraInfo = 0;
SendInput(1, key, sizeof(INPUT));
key->ki.dwExtraInfo = KEYEVENTF_KEYUP;
SendInput(1, key, sizeof(INPUT));
}
Het is de bedoeling dat hij de openstaande kladblok naar voorgrond zet en om de 10 seconden zegt dat C wordt ingedrukt..
Hij vindt de windows en zegt dat "C pressed." maar er verschijnt geen c in notepad..
Weet iemand wat ik fout doe?