does anyone know how to make a c++ program that types what you tell it to in to a text field on a website.

for example:

cout << "Hello";

how do you get this to print in to a text field on a website?

Recommended Answers

All 6 Replies

Member Avatar for iamthwee

Maybe try interfacing it with a library such as curl?

If you are using the Windows API, you can do this in a few ways.

  • Focus on the text box, and simulate keypresses.
  • Get the text box window handle, and set the text using SetWindowText
  • ... Probably more methods

Hope this helps.

i'm still quite new to c++ and i have no idea what curl is. please explain it more. thanks

:)

i use windows xp

idk what windows api is lol

:)

If you are using the Windows API, you can do this in a few ways.

  • Focus on the text box, and simulate keypresses.
  • Get the text box window handle, and set the text using SetWindowText
  • ... Probably more methods

Hope this helps.

can you explain in more detail plz

can you explain in more detail plz

The first method (probably easier) means you simply focus on the text box, and simulate key presses. Here's an example of how to do this on notepad.

#include <windows.h>

void SendKeys(char *keys) {
  while ( *keys )
    keybd_event( VkKeyScan(*keys++), 0, KEYEVENTF_EXTENDEDKEY, NULL );
}

int main() {
  system("start notepad.exe");
  HWND notepad = NULL;
  
  do {
    notepad = FindWindow( "Notepad", "Untitled - Notepad" );
    Sleep( 10 );

  } while ( notepad == NULL );

  Sleep( 500 );

  SetFocus( notepad );
  SendKeys( "hello world" );
}

Though your safer option would be the second method. Once you have found your window, it's very easy to edit the text in it, the hard part is finding it. To find one particular text box on a web browser, you have to know exactly what you're looking for (probably most accomplishable using EnumWindows). This is a tricky thing for a beginner, so I suggest you learn some basics first.

Though, on second thought, I'm not entirely sure how controls in web browsers work, so the second method may not work at all.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.