Questions regarding postmessage and keystroke.

  • (2 Pages)
  • +
  • 1
  • 2

15 Replies - 1761 Views - Last Post: 21 March 2013 - 07:04 AM Rate Topic: -----

#16 snoopy11  Icon User is offline

  • Engineering ● Software
  • member icon

Reputation: 773
  • View blog
  • Posts: 2,287
  • Joined: 20-March 10

Re: Questions regarding postmessage and keystroke.

Posted 21 March 2013 - 07:04 AM

View PostSkydiver, on 21 March 2013 - 12:35 PM, said:

I really suggest you pick up Petzold that I recommended above. You'll need basic information that is covered in the book.


Agreed.

Ok, necronox189

I will help you a little...

I am not going to give you exactly what you asked for

If you want that you are going to have to do a little work..

In this example I use SendInput to type something into a google search engine...

#include <windows.h>
#include <iostream>
#include <conio.h>
using namespace std;
HWND result;

BOOL CALLBACK EnumProc(HWND hwnd, LPARAM lParam) {


	char  word[256]= {0};
	GetWindowText(hwnd,word,255);

	char *pch;
	pch  = strstr(word,"Firefox");
	if(pch !=  NULL)
	{
		result = hwnd;

		cout << result << endl;
		return FALSE;//If return is FALSE; it stops the recursion
	}

	return TRUE; // must return TRUE; 
}



int main() 
{
	INPUT keyb;
	keyb.type  =1;
	keyb.ki.wVk  = 0x53;
	keyb.ki.dwFlags = 1;
	ShellExecute(NULL,"open","http://google.co.uk/",0,0,SW_SHOWNORMAL);
	Sleep(3000);//Wait  for firefox  to  open

	EnumWindows(EnumProc, 0);

	char  word[256]= {0};
	GetWindowText(result,word,255);
	cout << word << endl;

	SetForegroundWindow(result);
	Sleep(100);
	SendInput(1,&keyb,sizeof(keyb));
	Sleep(100);
	keyb.ki.wVk  = 0x4E;
	SendInput(1,&keyb,sizeof(keyb));
	Sleep(100);
	keyb.ki.wVk  = 0x4F;
	SendInput(1,&keyb,sizeof(keyb));
	Sleep(100);
	keyb.ki.wVk  = 0x4F;
	Sleep(100);
	SendInput(1,&keyb,sizeof(keyb));
	Sleep(100);
	keyb.ki.wVk  = 0x50;
	SendInput(1,&keyb,sizeof(keyb));
	Sleep(100);
	keyb.ki.wVk  = 0x59;
	SendInput(1,&keyb,sizeof(keyb));
	Sleep(100);
	keyb.ki.wVk  = VK_RETURN ;
	SendInput(1,&keyb,sizeof(keyb));
	cout << "Press Key to continue...";

	_getch();//used to hold window open replace as you see fit..
	return 0;
}





Its a bit of a quick and dirty way to do it...

There are more elegant ways..

Now I wonder what I will search for ..?? oooooh...

Snoopy.
Was This Post Helpful? 0
  • +
  • -

  • (2 Pages)
  • +
  • 1
  • 2