Click here to Skip to main content
15,300,160 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
hi, I am sending keystrokes to power point viewer through my application. When i give input to my application it scans input and sends the corresponding keystroke to P.P.viewer using sendmessage().
But the sendmessage() is not working. the input is not passed to the viewer. pls help me in sending input.also let me know where the mistake is.

here is my code:

C++
#include "stdafx.h"
#include "windows.h"
#include "stdio.h"
#define VK_N 0x4E
#define VK_P 0x50
#define WN_KEYUP 0x0101
#define WN_KEYDOWN 0x0100

int _tmain(int argc, _TCHAR* argv[])
{	
	char c;
	HWND hwnd;
	printf("make the target window topmost");
	Sleep(10000);  
	hwnd=GetForegroundWindow();
	//hwnd=FindWindow(NULL,PPTVIEW); 
	//if i want to use find window, how to get the classname and windowname of P.P.viewer??
	SetWindowPos(hwnd,HWND_TOPMOST,600,0,500,500,NULL);
	printf("\n caught handle now press p for previous slide and n for next slide");
	// now the input is given to my app which will scan and sendmessage to P.P.viewer.
	while(1)
	{
	scanf("%c",&c);
	switch(c)
		{
		case 'n':
			SendMessage(hwnd, WM_KEYDOWN, VK_N, 0);//this should take me to next slide
			flushall();
			break;
		case 'p':
			SendMessage(hwnd, WM_KEYDOWN, VK_P, 0);// this should take me to previous slide
			flushall();
			break;
		default:
			printf("enter n for next slide and p for previous slide");
			break;
		}
	}
	return 0;
}
Posted

In the above code Logically, it seems that you're making the Power Point window top most window (if you're using FindWindow). And still expecting to receive input to your application.

But actually when you run your application you end-up with receiving handle to your own window handle. (if you are using GetForegroundWindow() )
   
Thanks for helping.. I had found how to use findwindow. The below code should pass the keys to ppviewer, but it is not passing. pls tell me whether the parameters are incorrect or its problem with send message.

C++
#include "stdafx.h"
#include "windows.h"
#include "stdio.h"
#define VK_N 0x4E
#define VK_P 0x50
#define WN_KEYUP 0x0101
#define WN_KEYDOWN 0x0100
 
int _tmain(int argc, _TCHAR* argv[])
{	
	char c;
	HWND hwnd;
	hwnd=FindWindow(NULL,L"Powerpoint Viewer Slide Show - [Injection_Attacks.ppt]"); 
	printf("\n caught handle now press p for previous slide and n for next slide");
	// now the input is given to my app which will scan and sendmessage to P.P.viewer.
	while(1)
	{
	scanf("%c",&c);
	switch(c)
		{
		case 'n':
			SendMessage(hwnd, WM_KEYDOWN, VK_N, 0);//this should take me to next slide
			flushall();
			break;
		case 'p':
			SendMessage(hwnd, WM_KEYDOWN, VK_P, 0);// this should take me to previous slide
			flushall();
			break;
		default:
			printf("enter n for next slide and p for previous slide");
			break;
		}
	}
	return 0;
}
   
v2
Comments
Malli_S 24-May-12 3:54am
   
Check this http://msdn.microsoft.com/en-us/library/windows/desktop/ms646280(v=vs.85).aspx
Use the SendInput[^] function to inject keystrokes.
   
Comments
@bhinay 24-May-12 2:22am
   
it would be of great help if you tell me the mistake in above code

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900