Jump to content

C++ SendInput()


Dampe
 Share

Recommended Posts

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

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
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...