Results 1 to 8 of 8

Thread: PostMessage or SendMessage not working.

  1. #1

    Thread Starter
    Addicted Member Mal1t1a's Avatar
    Join Date
    Mar 2008
    Posts
    157

    PostMessage or SendMessage not working.

    First of all, is it even remotely possible to have PostMessage or SendMessage "press keys" inside of a Fullscreen game? I.e. use the Chat? (Requires the user to activate the chat box, type in the message, then send it, which is all done with the keyboard)

    I've tried many different ways using WM_KEYDOWN and WM_CHAR, and nothing worked.

    Code:
    Private Declare Function SendMessage Lib "user32" Alias "SendMessageA" ( _
        ByVal hwnd As Long, ByVal wMsg As Long, ByVal wParam As Integer, _
        ByVal lParam As Any) As Long
    I call it like this:

    Code:
    Dim myp = process.GetProcessByName("game")
    SendMessage(myp(0).handle, WM_CHAR, 13, 1&)
    Same goes for PostMessage, 13 is the keycode for Enter, and 1& is how many times I want it to be pressed. WM_CHAR sends the Message as a Character.

    I have tried the same as above with WM_KEYDOWN and changing 1& to 0&

    I am trying to get it to activate the user's chat by pressing enter, type in the text, then press enter again. Except, I would like for the game to be minimized and allow this to work. Or, if while the game was running in fullscreen, that I was able to use SendMessage or PostMessage to type text into a Command Prompt Window.

    Thanks.

  2. #2
    Karen Payne MVP kareninstructor's Avatar
    Join Date
    Jun 2008
    Location
    Oregon
    Posts
    6,714

    Re: PostMessage or SendMessage not working.

    Here is an example of pressing a button in an external application called ColorCop.

    Code:
    Module ColorCop_Sending
        Private Declare Function FindWindow Lib "user32.dll" _
            Alias "FindWindowA" (ByVal lpClassName As String, _
                                 ByVal lpWindowName As String) As IntPtr
    
        Private Declare Function FindWindowEx Lib "user32.dll" _
            Alias "FindWindowExA" (ByVal hWndParent As IntPtr, _
                                   ByVal hWndChildAfter As Integer, _
                                   ByVal lpClassName As String, _
                                   ByVal lpWindowName As String) As IntPtr
    
        Private Declare Function SendMessage Lib "user32.dll" _
            Alias "SendMessageA" (ByVal hWnd As IntPtr, _
                                  ByVal wMsg As Integer, _
                                  ByVal wParam As Integer, _
                                  ByVal lParam As IntPtr) As IntPtr
    
        Const BM_CLICK As Integer = &HF5
    
        Public Sub Demo1()
            Dim ColorCophwnd As IntPtr = FindWindow(vbNullString, "Color Cop 5.3")
            If ColorCophwnd <> IntPtr.Zero Then
                Dim CustomButton As IntPtr = FindWindowEx(ColorCophwnd, 0, "Button", "&Custom")
                If CustomButton <> IntPtr.Zero Then
                    SendMessage(CustomButton, BM_CLICK, 0, IntPtr.Zero)
                End If
            End If
        End Sub
    
    End Module
    ColorCop download http://colorcop.net/download

    Note to try out the demo above you need to change the version used in red above as I am using an older version of ColorCop.

  3. #3

    Thread Starter
    Addicted Member Mal1t1a's Avatar
    Join Date
    Mar 2008
    Posts
    157

    Re: PostMessage or SendMessage not working.

    How could I apply that to typing to a Console Window? Or to Typing to a Fullscreen game? From what I gather from your code:

    Code:
    FindWindowEx(ColorCophwnd, 0, "Button", "&Custom")
    The "Button" is specifying what type of control it is. and the "&Custom" is specifying what value it holds.

    To typing to a Console Window, I wouldn't know how I would do that, or how I would type to a fullscreen game, using your code. Can you help me with that?

    I can get the Handle of the Process using process.getProcessesByName("game")(0).handle, if that works.
    Last edited by Mal1t1a; Apr 27th, 2011 at 11:30 PM.

  4. #4

    Thread Starter
    Addicted Member Mal1t1a's Avatar
    Join Date
    Mar 2008
    Posts
    157

    Re: PostMessage or SendMessage not working.

    Typing to a console window is solved by using Process.GetProcessesByName("cmd")(0).MainWindowHandle

    How I am still unable to type into a fullscreen game. When the fullscreen game is open, and set to focus, using SendKeys.Send() works.

  5. #5
    Karen Payne MVP kareninstructor's Avatar
    Join Date
    Jun 2008
    Location
    Oregon
    Posts
    6,714

    Re: PostMessage or SendMessage not working.

    Quote Originally Posted by Mal1t1a View Post
    How could I apply that to typing to a Console Window? Or to Typing to a Fullscreen game? From what I gather from your code:

    Code:
    FindWindowEx(ColorCophwnd, 0, "Button", "&Custom")
    The "Button" is specifying what type of control it is. and the "&Custom" is specifying what value it holds.

    To typing to a Console Window, I wouldn't know how I would do that, or how I would type to a fullscreen game, using your code. Can you help me with that?

    I can get the Handle of the Process using process.getProcessesByName("game")(0).handle, if that works.
    The code finds a window then a control under that window handle which would not exists if you are sending commands to a console app. If your app is a console app than what I gave should work against a non-console app.

  6. #6

    Thread Starter
    Addicted Member Mal1t1a's Avatar
    Join Date
    Mar 2008
    Posts
    157

    Re: PostMessage or SendMessage not working.

    What about a DirectX Game? What kind of control handle could I get from there to direct the input to the actual game?
    Last edited by Mal1t1a; Apr 28th, 2011 at 08:06 PM.

  7. #7
    Karen Payne MVP kareninstructor's Avatar
    Join Date
    Jun 2008
    Location
    Oregon
    Posts
    6,714

    Re: PostMessage or SendMessage not working.

    Quote Originally Posted by Mal1t1a View Post
    What about a DirectX Game? What kind of control handle could I get from there to direct the input to the actual game?
    I have not worked with coding for games so I have nothing to suggest.

  8. #8

    Thread Starter
    Addicted Member Mal1t1a's Avatar
    Join Date
    Mar 2008
    Posts
    157

    Re: PostMessage or SendMessage not working.

    Bump. I'm still looking for some other way to do this. The only thing I can do, is use SendKeys.SendWait("{enter}")

    which even then, doesn't work all the time.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width