#1
  1. Junior Member
    Devshed Newbie (0 - 499 posts)

    Join Date
    Oct 2002
    Posts
    2
    Rep 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.
  2. #2
  3. Banned ;)
    Devshed Supreme Being (6500+ posts)

    Join Date
    Nov 2001
    Location
    Woodland Hills, Los Angeles County, California, USA
    Posts
    9,638
    Rep Power
    4247
    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! :)
  4. #3
  5. No Profile Picture
    Offensive Member
    Devshed Novice (500 - 999 posts)

    Join Date
    Oct 2002
    Location
    in the perfect world
    Posts
    622
    Rep Power
    27
    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

IMN logo majestic logo threadwatch logo seochat tools logo