Dampe Posted March 3, 2009 Share Posted March 3, 2009 I'm attempting to learn some more Windows API stuff with c++.. Can anyone tell me why this wont send any keys to the window once it has activated? #define _WIN32_WINNT 0x0501 #include <windows.h> #include <iostream> using namespace std; int main() { char end; HWND windowHandle = FindWindow(0, "Untitled - Notepad"); INPUT *key; if(windowHandle == NULL) cout << "not found"; SetForegroundWindow(windowHandle); Sleep(1000); key = new INPUT; key->type = INPUT_KEYBOARD; key->ki.wVk = 41; 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)); cout << "key inputted"; cin >> end; cin.get(); return 0; } Link to comment Share on other sites More sharing options...
Richard Robertson Posted March 3, 2009 Share Posted March 3, 2009 It is doing something. It's sending the key up event. You have to press a key down first, then wait some period of time, then let it up. Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now