Findwindow Sendmessage Help

This is a discussion on Findwindow Sendmessage Help within the Windows Programming forums, part of the Platform Specific Boards category; In these circumstances, I'd load the application your trying to control into a debugger, fake the window message and watch ...

  1. #16
    Registered User
    Join Date
    Jun 2003
    Posts
    245
    In these circumstances, I'd load the application your trying to control into a debugger, fake the window message and watch what happens to it, and then do a real keypress and watch. You should then be able to tell what you need to do in order to "fool" the program into accepting the keypress.

    If it's a chat-type program, then it most likely will ignore all ascii and virtual keys, and use the scancode instead, asking the system to translate the key for it, to maintain compatibility. This is certainly the way I'd do it.

  2. #17
    Registered User
    Join Date
    Jul 2003
    Posts
    110
    scancode?

    Is this a hex or decimal?

    How big can a scancode be?

    I reason I ask is, im 99% sure u can run this program in debugger mode, because you have to open a diffrent program that links to the main program in runtime. YOu cant jump to the other program because it sends information to the main client.

    So, if I can figure out how to send a scancode, then ill just make a big for loop that sends everynumber in its MAX size to the client until it says something :/.

    Is this possiable?

    How does one send a scancode?

  3. #18
    It's full of stars adrianxw's Avatar
    Join Date
    Aug 2001
    Posts
    4,831
    The hardware scan code is an 8bit value. There is a program that will return the scan code of a key at the bottom of part 6 of my tutorial here.
    Wave upon wave of demented avengers march cheerfully out of obscurity unto the dream.

  4. #19
    Registered User
    Join Date
    Jun 2003
    Posts
    245
    bits 16-23 of WM_CHAR's lparam is the scan code.

  5. #20
    Registered User
    Join Date
    Jul 2003
    Posts
    110
    So

    WM_CHAR

    WPARAM wParam
    LPARAM lParam;

    takes in that.

    My scancode value for Enter is '1c' or '28'

    and my Lparm can be anything between 16-28 depending on my OEM.
    Im guessing my OEM code is '437'.

    so what is my wParm.

    in
    Code:
    wParm = 0x1c;  //Scancode value for 'Enter Key'
    for(i=16;i<29;i++)
    SendMessage(hwnd,WM_CHAR,wParm,i);
    Then I tryed
    Code:
    wParm = 97;
    for(i=16;i<29;i++)
    SendMessage(hwnd,WM_CHAR,wParm,i);
    Then I realized its still taking the ANSI value for the wParm.
    and it still printed out the aaaaaaaaa in the chat bar.

    How do I send the scancode value?

    Update I just send this and still nothing.
    Code:
    for(i=16;i<29;i++)
                for(z=0;z<300;z++)
    		SendMessage(hwnd,WM_CHAR,z,i);
    Last edited by Coder87C; 08-10-2003 at 02:39 PM.

  6. #21
    mustang benny bennyandthejets's Avatar
    Join Date
    Jul 2002
    Posts
    1,401
    Did you use Elixia's method yet? What I would do is get into Spy++, and intercept all messages to the control. Press the enter key, and then with you program just mimic the same messages.
    benforbes@optusnet.com.au
    Microsoft Visual Studio .NET 2003 Enterprise Architect
    Windows XP Pro

    Code Tags
    Programming FAQ
    Tutorials

  7. #22
    mustang benny bennyandthejets's Avatar
    Join Date
    Jul 2002
    Posts
    1,401
    I used the technique, and got the following:

    WM_KEYDOWN, nVirtKey=VK_RETURN, ScanCode=1C
    WM_CHAR chCharCode=13, ScanCode=1C
    WM_KEYUP, nVirtKey=VK_RETURN, ScanCode=1C

    There was also some other variables for each message, but you can find those out yourself. So basically, you should just send the messages exactly as listed in a program like Spy++.
    benforbes@optusnet.com.au
    Microsoft Visual Studio .NET 2003 Enterprise Architect
    Windows XP Pro

    Code Tags
    Programming FAQ
    Tutorials

  8. #23
    Registered User
    Join Date
    Jul 2003
    Posts
    110

    Hey

    I guess I should have said something when I didnt know how to use the message getter in Spy++. I had the wrong version, so I did a search and found the right one...

    So I got this.

    http://www.battleoftheoutlaws.com/images/OUTPUT.gif


    It might be hard to read, im a new user with Spy++ and have figured out how to filter out all the crap (i got rid of some mouse stuff ect.)

    Now with my ability I duplicated the message like this.

    Code:
    #include <windows.h>
    #include <stdio.h>
    int main(void)
    {	
    	
    	HWND hwnd = 0;
    	 
    	//Get main notepad handle
    	while(hwnd==0)
    		hwnd = FindWindow("SwgClient",NULL);
    
    
    SendMessage(hwnd,WM_KEYDOWN,'A',0);
    SendMessage(hwnd,WM_CHAR,'A',0);
    SendMessage(hwnd,WM_KEYUP,'A',0);
    
    SendMessage(hwnd,WM_KEYDOWN,VK_RETURN,0);
    SendMessage(hwnd,WM_CHAR,13,0);
    SendMessage(hwnd,WM_KEYUP,VK_RETURN,0);
    
    SendMessage(hwnd,WM_KEYDOWN,'B',0);
    SendMessage(hwnd,WM_CHAR,'B',0);
    SendMessage(hwnd,WM_KEYUP,'B',0);
    
    SendMessage(hwnd,WM_KEYDOWN,VK_RETURN,0);
    SendMessage(hwnd,WM_CHAR,13,0);
    SendMessage(hwnd,WM_KEYUP,VK_RETURN,0);
    
    SendMessage(hwnd,WM_KEYDOWN,'C',0);
    SendMessage(hwnd,WM_CHAR,'C',0);
    SendMessage(hwnd,WM_KEYUP,'C',0);
    
    SendMessage(hwnd,WM_KEYDOWN,VK_RETURN,0);
    SendMessage(hwnd,WM_CHAR,13,0);
    SendMessage(hwnd,WM_KEYUP,VK_RETURN,0);
    
    SendMessage(hwnd,WM_KEYDOWN,'D',0);
    SendMessage(hwnd,WM_CHAR,'D',0);
    SendMessage(hwnd,WM_KEYUP,'D',0);
    
    SendMessage(hwnd,WM_KEYDOWN,VK_RETURN,0);
    SendMessage(hwnd,WM_CHAR,13,0);
    SendMessage(hwnd,WM_KEYUP,VK_RETURN,0);
    
    SendMessage(hwnd,WM_SYSKEYDOWN,VK_MENU,0);
    
    SendMessage(hwnd,WM_CANCELMODE,0,0);
    SendMessage(hwnd,WM_CANCELMODE,0,0);
    
    SendMessage(hwnd,WM_KEYUP,VK_MENU,0);	
    
    	return 0; 
    }
    Now when this runs. It prints out in the chat box.

    "ABCD"

    no return key was pushed? I also see a lot of extra stuff in the output of the message. Could someone tell me what im missing.


    Coder87

  9. #24
    It's full of stars adrianxw's Avatar
    Join Date
    Aug 2001
    Posts
    4,831
    Has it occured to you that the author of the target program may well be looking for certain "key presses" and treating them in HIS windows loop in a particular way?
    Wave upon wave of demented avengers march cheerfully out of obscurity unto the dream.

  10. #25
    Registered User
    Join Date
    Jun 2003
    Posts
    245
    You are still only sending half a keystroke, as you are sending lparam as 0 (which contains the repeat count, scan code, extended-key flag, context code, previous key-state flag, and transition-state flag). The program may well be noticing this and therefore completely ignoring your message.

  11. #26
    Registered User
    Join Date
    Jul 2003
    Posts
    110
    Code:
    SendMessage(hwnd,WM_KEYDOWN,0x00000041,0x001E0001);
    SendMessage(hwnd,WM_CHAR,0x00000041,0x001E0001);
    SendMessage(hwnd,WM_KEYUP,0x00000041,0xc01E0001);
    
    SendMessage(hwnd,WM_KEYDOWN,0x0000000d,0x001c0001);
    SendMessage(hwnd,WM_CHAR,0x0000000d,0x001c0001);
    SendMessage(hwnd,WM_KEYUP,0x0000000d,0xc01c0001);
    Is there a way to trick a system in thinking the key was pressed even thought it is looking for it?

    It prints the letters in the Box, but still isnt executing command buttons like Enter.

    Is this a lose cause?

  12. #27
    Registered User
    Join Date
    Jun 2003
    Posts
    245
    Try to find a keyboard macro recorder, and see how it works, and if it does the return key for you.

Page 2 of 2 FirstFirst 12
Popular pages Recent additions subscribe to a feed

Similar Threads

  1. SendMessage
    By reefa in forum Windows Programming
    Replies: 15
    Last Post: 07-18-2005, 03:36 PM
  2. Combobox problem
    By gargamel in forum Windows Programming
    Replies: 2
    Last Post: 05-06-2005, 01:37 PM
  3. WM_KEYDOWN and SendMessage
    By Unregistered in forum Windows Programming
    Replies: 4
    Last Post: 07-13-2002, 05:23 PM
  4. FindWindow()
    By face_master in forum Windows Programming
    Replies: 2
    Last Post: 05-27-2002, 11:53 AM
  5. SendMessage causes an exception in release.
    By DS in forum Windows Programming
    Replies: 1
    Last Post: 11-27-2001, 10:34 AM

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