Kladblok autotyper

Status
Niet open voor verdere reacties.

Arjan B

Gebruiker
Lid geworden
11 dec 2006
Berichten
364
Ik heb deze code:
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?
 
je gebruikt SendInput (heb hier geen windows sdk, dus wat dat ook moge zijn). Ik denk dat PostMessage(HWndEdit, WM_KEYDOWN, ? , ? ) wel werkt onder windows versies voor vista. Ik meen dat vista het zenden van messages tussen verschillende applicaties niet toestaat....
 
als ik PostMessage gebruik moet het 3e argument (wParam) VK_C worden. maar wat moet ik dan voor het 4e argument invullen?
 
Code:
#include <windows.h>
#include <iostream>

#define VK_C 43

using std::cin;
using std::cout;

int main()
{
    cout << "Press a key to start.";
    cin.get();
    
    HWND hWndKladBlok= FindWindow(NULL, "Naamloos - Kladblok"); //Find kladblok
    if(hWndKladBlok== NULL){ cout << "Could not find Kladblok.\n"; cin.get(); return 0;}
    HWND hWndEdit= GetWindow(hWndKladBlok, GW_CHILD); //Get edit window
    if(hWndEdit== NULL){ cout << "Could not find child window.\n"; cin.get(); return 0;}
    SetForegroundWindow(hWndEdit);
    
    while(1)
    {
        PostMessage(hWndEdit, WM_KEYDOWN, VK_C, NULL);
        cout << "C Pressed.\n";
        Sleep(10000);
    }
    
    return 0;
}

Deze code werkt nog steeds niet.
Code:
PostMessage(hWndEdit, WM_KEYDOWN, (WPARAM)VK_C, NULL);
Werkt ook niet..
 
Laatst bewerkt:
..Ik gebruikte vroeger altijd SendMessage, ik weet niet of dat verschil maakt.
 
Status
Niet open voor verdere reacties.
Terug
Bovenaan Onderaan