sending keys

This is a discussion on sending keys within the Windows Programming forums, part of the Platform Specific Boards category; I just can't get it to work... can anyone tell me the code they would use to send a key ...

  1. #1
    Registered User canine's Avatar
    Join Date
    Sep 2001
    Posts
    125

    Question sending keys

    I just can't get it to work... can anyone tell me the code they would use to send a key to something like notepad and have it read it as if it were you hitting a key on the keyboard?
    In a perfect world every dog would have a home and every home would have a dog.
    Visit My Web Site, Canine Programming
    I use Win32 API

  2. #2
    zen
    zen is offline
    of Zen Hall zen's Avatar
    Join Date
    Aug 2001
    Posts
    1,007
    Like this -

    Code:
    #include <windows.h>
    
    int main()
    {
    
    	HWND hwnd=0;
    
    	//Get main notepad handle
    	while(hwnd==0)
    		hwnd = FindWindow("Notepad",0);
    
    	HWND hwndEdit =0;
    
    	//Get notepad edit control
    	while(hwndEdit==0)
    		hwndEdit = FindWindowEx(hwnd,0,"edit",0);
    
    	//write an 'a'
    	TCHAR test = 'a';
    	SendMessage(hwndEdit,WM_CHAR,test,0);
    
    	return 0; 
    }
    zen

  3. #3
    Registered User canine's Avatar
    Join Date
    Sep 2001
    Posts
    125

    Smile

    It worked!! Thank you so much!
    In a perfect world every dog would have a home and every home would have a dog.
    Visit My Web Site, Canine Programming
    I use Win32 API

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Simulate Keys with a Keyboard Hook
    By guitarist809 in forum Windows Programming
    Replies: 3
    Last Post: 11-14-2008, 08:14 PM
  2. blocking or passing keys with global hook
    By pmouse in forum Windows Programming
    Replies: 4
    Last Post: 08-29-2007, 03:54 PM
  3. Interfacing with arrow keys...
    By adityakarnad in forum Game Programming
    Replies: 1
    Last Post: 08-30-2003, 11:25 PM
  4. Sending keys to an AOL IM window?
    By SyntaxBubble in forum Windows Programming
    Replies: 0
    Last Post: 11-05-2001, 03:45 PM
  5. Arrow Keys and Such
    By Thantos in forum Game Programming
    Replies: 5
    Last Post: 10-25-2001, 06:40 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21