Thread: Sending a String to a Window

  1. #1
    Registered User
    Join Date
    Aug 2003
    Posts
    288

    Post Sending a String to a Window

    Im working on a program that sends a string to the specified window, like an auto-typer.

    So far ive finished the code to actually find the HWND of the window i want to send the string to.

    Ive tried it out using notepad and it works fine:


    Code:
    SendMessage(hWnd, WM_CHAR, 65, 0);
    Notepad seems to work fine with this, but when i try using:


    Code:
    SendMessage(hWnd, WM_KEYUP, 45, 0);
    SendMessage(hWnd, WM_KEYDOWN, 45, 0);
    nothing happens...

    I think it might be a problem with the lParam, but i have no idea what value to set it to, i checked MSDN and my Win32 API Documentation, and they give me this table that i really didnt understand.

    Also, i do not want to use keybd_event or SendInput since they require the program to be in focus.

    Ive used Spy++ to see what messages get sent while normally using the program, and it sends WM_KEYDOWN then WM_CHAR then WM_KEYUP, ive tried doing that in the same order, but it doesnt show up.

    Notepad only received input when i sent the WM_CHAR message, so im trying to find out what value i have to pass into lParam to make it work.

    (I know its only a notification message, but i really dont know any other way, if theres a way to actually send the input to the program without it being in focus, then could someone please post it)

    Thanks,

    PaYnE

  2. #2
    Software Developer jverkoey's Avatar
    Join Date
    Feb 2003
    Location
    New York
    Posts
    1,905
    in openscript's IDE, i use sendmessage with a WM_CHAR message to set the tab spacing, and i do this:

    Code:
    SendMessage(EditBox,WM_CHAR,VK_TAB,NULL);
    and that seems to work fine. WM_CHAR from what i've read is basically the same thing as pressin up/down at once, except it basically tells the edit box that you went through the whole motion.....methinks....msdn search might help....

    http://msdn.microsoft.com/library/de...es/wm_char.asp
    wheee! ^^

  3. #3
    Registered User
    Join Date
    Aug 2003
    Posts
    288
    That works fine in notepad, but in the program im trying to send the string to, it doesnt do a thing.

    As i said Spy++ shows that it receives 3 messages (keydown, char, and keyup) when u type sumthing manually, ive tried doing that programmatically and nothing happens.

    Maybe its due to the fact that its just a notification message, or that Im not using the right values, because it doesnt work in notepad either (except for WM_CHAR).

    But thanks for the reply anyways.

  4. #4
    Registered User
    Join Date
    Aug 2003
    Posts
    288
    And about the MSDN thing:


    lParam
    Specifies the repeat count, scan code, extended-key flag, context code, previous key-state flag, and transition-state flag, as shown in the following table.
    0-15
    Specifies the repeat count for the current message. The value is the number of times the keystroke is autorepeated as a result of the user holding down the key. If the keystroke is held long enough, multiple messages are sent. However, the repeat count is not cumulative.
    16-23
    Specifies the scan code. The value depends on the OEM.
    24
    Specifies whether the key is an extended key, such as the right-hand ALT and CTRL keys that appear on an enhanced 101- or 102-key keyboard. The value is 1 if it is an extended key; otherwise, it is 0.
    25-28
    Reserved; do not use.
    29
    Specifies the context code. The value is 1 if the ALT key is held down while the key is pressed; otherwise, the value is 0.
    30
    Specifies the previous key state. The value is 1 if the key is down before the message is sent, or it is 0 if the key is up.
    31
    Specifies the transition state. The value is 1 if the key is being released, or it is 0 if the key is being pressed.
    I dont understand a THING that says: does it mean if u use one of those values? or do u need a structure or sumthing and u have to use all of those values? could someone please explain?

  5. #5
    It's full of stars adrianxw's Avatar
    Join Date
    Aug 2001
    Posts
    4,829
    Perhaps the program you are sending to only processes WM_CHAR messages and it hasn't got a call to TranslateMessage() in it's dispatch loop? Difficult to say on what's been given.
    Wave upon wave of demented avengers march cheerfully out of obscurity unto the dream.

  6. #6
    Registered User
    Join Date
    Aug 2003
    Posts
    288
    hmm to make a long question short:
    what value do i use for the lParam, and why?

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Replies: 8
    Last Post: 04-25-2008, 02:45 PM
  2. Inheritance Hierarchy for a Package class
    By twickre in forum C++ Programming
    Replies: 7
    Last Post: 12-08-2007, 04:13 PM
  3. Message class ** Need help befor 12am tonight**
    By TransformedBG in forum C++ Programming
    Replies: 1
    Last Post: 11-29-2006, 11:03 PM
  4. Program using classes - keeps crashing
    By webren in forum C++ Programming
    Replies: 4
    Last Post: 09-16-2005, 03:58 PM
  5. opengl help
    By heat511 in forum Game Programming
    Replies: 4
    Last Post: 04-05-2004, 01:08 AM