Sign in to follow this  
Followers 0
Dampe

C++ SendInput()

2 posts in this topic

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;
}

Share this post


Link to post
Share on other sites



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.

Share this post


Link to post
Share on other sites

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 account

Sign in

Already have an account? Sign in here.


Sign In Now
Sign in to follow this  
Followers 0