C Programming
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me
Go Back   Dev Shed ForumsProgramming LanguagesC Programming

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Dev Shed Forums Sponsor:
  #1  
Old October 31st, 2002, 08:31 AM
jattie's Avatar
jattie jattie is offline
Junior Member
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Oct 2002
Posts: 2 jattie User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
Passing fake keystrokes to a third part application

This is what I've been able to learn so far with regard to sending keystrokes from my c program to a third part executable application. In summary I basically get the handle to the application and simply send it a message using that handle and the message format is determined by the output captured using a handy application spy.exe that can be found in the MS SDK distribution. This message is repeated by my code but nothing happens in the third party application. For some reason unknown (and undocumented by M$) it simply does not respond. My guess is that it has to do with the handle of the message sender and I have to assume that it is a handle (00170448) that's in front of spy's output because it's not described in the M$ documentation as well. The only difference I can see is the handle/ID being different and the keydown capture handle in the capture sequence is different.

So if anyone can help me to make some progress beyond this, please let me know, any suggestions or ideas welcomed!

Code:

/*
captured code
00170448	WM_KEYDOWN	00000011	001D0001 
00170448	WM_KEYDOWN	00000053	001F0001 
00170448	WM_CHAR		00000013	001F0001 
00050514	WM_KEYUP		00000053	C01F0001 
00050514	WM_KEYUP		00000011	C01D0001 
result of my program code
0019044E	WM_KEYDOWN	00000011	001D0001 
0019044E	WM_KEYDOWN	0000004F	00180001 
0019044E	WM_CHAR		0000000F	00180001 
0019044E	WM_KEYUP		0000004F	C0180001 
0019044E	WM_KEYUP		00000011	C01D0001 
*/
 


#include "windows.h"
#include "toolbox.h"
#include <ansi_c.h>
#include <utility.h>
#include <cvirte.h>
 

int __stdcall WinMain (HINSTANCE hInstance, HINSTANCE hPrevInstance,
					   LPSTR lpszCmdLine, int nCmdShow)
{
	int ExeHandle;
	HWND WindowHandle;
	LRESULT Result;
	WPARAM WParam;
	LPARAM LParam;
	
	//launch my application here 


	LaunchExecutableEx ("Notepad.exe WinMSG.txt", LE_SHOWNORMAL,&ExeHandle);
	//wiat a while before getting the handle else it return NULL 

	Delay(1);
	//get the handle to the application 

	WindowHandle = FindWindow(
					  	"Notepad",			//LPCTSTR lpClassName - class name 

					  	"WinMSG.txt - Notepad"//LPCTSTR lpWindowName - window name 

						);
	//Key sequence captured with Spy.exe - what happens when you hit <ctrl>S in 

	//a notepad window and you get the save dialogue
	/*
	00170448	WM_KEYDOWN	00000011	001D0001 
	00170448	WM_KEYDOWN	00000053	001F0001 
	00170448	WM_CHAR		00000013	001F0001 
	00050514	WM_KEYUP		00000053	C01F0001 
	00050514	WM_KEYUP		00000011	C01D0001 
	*/

	//This code produces the exact same results in spy, but no result in notepad 

	WParam=0x11;
	LParam=0x1D0001;
	Result = SendMessage(WindowHandle,WM_KEYDOWN,WParam,LParam);
	
	WParam=0x4F;
	LParam=0x180001;
	Result = SendMessage(WindowHandle,WM_KEYDOWN,WParam,LParam);
	
	
	WParam=0xF;
	LParam=0X180001;
	Result = SendMessage(WindowHandle,WM_CHAR,WParam,LParam);
	
	WParam=0x4F;
	LParam=0xC0180001;
	Result = SendMessage(WindowHandle,WM_KEYUP,WParam,LParam);
	
	WParam=0x11;
	LParam=0xC01D0001;
	Result = SendMessage(WindowHandle,WM_KEYUP,WParam,LParam);
	
	
	Delay(5);
	TerminateExecutable (ExeHandle);
	RetireExecutableHandle (ExeHandle);
	
	return 0;
}


Last edited by jattie : October 31st, 2002 at 08:34 AM.

Reply With Quote
  #2  
Old November 1st, 2002, 05:10 PM
Scorpions4ever's Avatar
Scorpions4ever Scorpions4ever is offline
Banned ;)
Dev Shed God 6th Plane (7500 - 7999 posts)
 
Join Date: Nov 2001
Location: Glendale, Los Angeles County, California, USA
Posts: 7,589 Scorpions4ever User rank is General (90000 - 100000 Reputation Level)Scorpions4ever User rank is General (90000 - 100000 Reputation Level)Scorpions4ever User rank is General (90000 - 100000 Reputation Level)Scorpions4ever User rank is General (90000 - 100000 Reputation Level)Scorpions4ever User rank is General (90000 - 100000 Reputation Level)Scorpions4ever User rank is General (90000 - 100000 Reputation Level)Scorpions4ever User rank is General (90000 - 100000 Reputation Level)Scorpions4ever User rank is General (90000 - 100000 Reputation Level)Scorpions4ever User rank is General (90000 - 100000 Reputation Level)Scorpions4ever User rank is General (90000 - 100000 Reputation Level)Scorpions4ever User rank is General (90000 - 100000 Reputation Level)Scorpions4ever User rank is General (90000 - 100000 Reputation Level)Scorpions4ever User rank is General (90000 - 100000 Reputation Level)Scorpions4ever User rank is General (90000 - 100000 Reputation Level)Scorpions4ever User rank is General (90000 - 100000 Reputation Level)Scorpions4ever User rank is General (90000 - 100000 Reputation Level) 
Time spent in forums: 1 Month 1 Day 22 h 40 m 58 sec
Reputation Power: 1001
Send a WM_COMMAND with wID = 1 to the Notepad window
Code:
SendMessage(WindowHandle, WM_COMMAND, 1, 0);

I found this by using Spy++ on the Window handle. BTW if you want to send commands to the Edit window of Notepad, then you have to find the handle of the Edit window itself, rather than the handle of the application. You can do this with a EnumChildWindows(). Hope this helps!

Reply With Quote
  #3  
Old November 4th, 2002, 12:16 AM
TechNoFear TechNoFear is offline
Offensive Member
Dev Shed Novice (500 - 999 posts)
 
Join Date: Oct 2002
Location: in the perfect world
Posts: 594 TechNoFear User rank is Sergeant (500 - 2000 Reputation Level)TechNoFear User rank is Sergeant (500 - 2000 Reputation Level)TechNoFear User rank is Sergeant (500 - 2000 Reputation Level)TechNoFear User rank is Sergeant (500 - 2000 Reputation Level)TechNoFear User rank is Sergeant (500 - 2000 Reputation Level) 
Time spent in forums: 2 Days 14 h 6 m 15 sec
Reputation Power: 21
Could be the app is protecting it self with

InSendMessageEx()


and ignoring your messages (as any professional app should)
__________________
The essence of Christianity is told us in the Garden of Eden history. The fruit that was forbidden was on the Tree of Knowledge. The subtext is, All the suffering you have is because you wanted to find out what was going on. You could be in the Garden of Eden if you had just kept your f***ing mouth shut and hadn't asked any questions.

Frank Zappa

Reply With Quote
Reply

Viewing: Dev Shed ForumsProgramming LanguagesC Programming > Passing fake keystrokes to a third part application


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump


Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 





© 2003-2008 by Developer Shed. All rights reserved. DS Cluster 2 hosted by Hostway
Stay green...Green IT