Sign in to follow this  
X5-Programmer

SendKeys.

Recommended Posts

X5-Programmer    100
I have a question about sending keys... I have try to make a program that you can type in a text in a dialog box, and then make it write the text into notepad. but the only function I can find is keybd_event in msdn.. but it only takes, VK_KEYS.. how can I do this if I whant to send a string? like this. char string[5] = {"test"}; for(int i=0; i < strlen(string) + 1; i++){ sendKeySomehow(string[i]); } you know what I mean... hope anyone can point me somewere..

Share this post


Link to post
Share on other sites
master of void    122

#include <windows.h>
#include <iostream>
#include <string.h>
#include<conio.h>

using namespace std;

int main(){
HWND notepad_window = FindWindow("Notepad", NULL);
HWND textbox_window = FindWindowEx(notepad_window, NULL, "Edit", NULL);

if (!notepad_window) {
printf("Could not find Notepad\n");
system("Pause");
return 1;
}


string my_string;

cout << "Enter a word to send to Notepad: ";
cin >> my_string;

for (int i = 0; i < my_string.size(); i++)
SendMessage(textbox_window, WM_CHAR, (int)my_string[i], 0x80000000);
return 0;
}


If i have understood you corectly this code should help.
You just have to change it so you enter the text in a dialogbox instead of in a console window.

hope it helps

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