Beste lezers,
Ik probeer een keystroke te sturen naar mijn programma, echter gebeurd er niks! als ik sendkey of zo gebruik dan wel alleen ik wil dat het scherm niet persé gefocust hoeft te zijn als ik iets verstuur. Vandaar dat mij verteld werd PostMessage te gebruiken.
Hopelijk kan iemand mij vertellen wat ik verkeerd doe
Mijn code:
[CPP] // bring the window to the front
HWND GameWindow = FindWindow(0, L"Naamloos - Kladblok");
SetForegroundWindow(GameWindow);
// execute the loop
for( int i = 0; i < amount; i++ ){
// not the last loop so add a pause at the end
if( i < (amount-1))
{
PostMessage(GameWindow, WM_KEYDOWN, 'G', 0);
PostMessage(GameWindow, WM_KEYUP, 'G', 0);
Sleep(2000);
}
// last loop so dont add a pause at the end
else
{
PostMessage(GameWindow, WM_KEYDOWN, 'G', 0);
PostMessage(GameWindow, WM_KEYUP, 'G', 0);
}
}[/CPP]
Alles klopt en werkt alleen de PostMessage functie niet.
Groetjes
P.S. Ik zit op Windows en gebruik Qt
Ik probeer een keystroke te sturen naar mijn programma, echter gebeurd er niks! als ik sendkey of zo gebruik dan wel alleen ik wil dat het scherm niet persé gefocust hoeft te zijn als ik iets verstuur. Vandaar dat mij verteld werd PostMessage te gebruiken.
Hopelijk kan iemand mij vertellen wat ik verkeerd doe
Mijn code:
[CPP] // bring the window to the front
HWND GameWindow = FindWindow(0, L"Naamloos - Kladblok");
SetForegroundWindow(GameWindow);
// execute the loop
for( int i = 0; i < amount; i++ ){
// not the last loop so add a pause at the end
if( i < (amount-1))
{
PostMessage(GameWindow, WM_KEYDOWN, 'G', 0);
PostMessage(GameWindow, WM_KEYUP, 'G', 0);
Sleep(2000);
}
// last loop so dont add a pause at the end
else
{
PostMessage(GameWindow, WM_KEYDOWN, 'G', 0);
PostMessage(GameWindow, WM_KEYUP, 'G', 0);
}
}[/CPP]
Alles klopt en werkt alleen de PostMessage functie niet.
Groetjes
P.S. Ik zit op Windows en gebruik Qt
Laatst bewerkt: