Problem with Keys menu

User Tag List

Page 2 of 2 FirstFirst 12
Results 16 to 21 of 21
  1. #16
    schifers's Avatar Member
    Reputation
    2
    Join Date
    Sep 2008
    Posts
    17
    Thanks G/R
    0/1
    Trade Feedback
    0 (0%)
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Originally Posted by xzidez View Post
    SendMessage works just fine. However you must be sending it till the handle of the window. Not the wow process itself.

    In other words the handle you will get if you use FindWindow(null, "World of Warcraft");
    When I start WoW process using the class Process from the .NET framework, I have an attribute in this class named MainWindowHandle. I can handle the window with this pointer I guess. I don't think I need to use FindWindow.

    So, after the WoW process starts, I use WaitForInputIdle and I start to send messages through PostMessage. I tried using SendMessage with no success, so I stick with PostMessage. If I use FindWindow, will I have another result? Is it the same handle that I get through MainWindowHandle?
    Last edited by schifers; 10-06-2009 at 11:45 AM.

    Problem with Keys
  2. #17
    RiotInferno's Avatar Member
    Reputation
    4
    Join Date
    Aug 2009
    Posts
    10
    Thanks G/R
    0/0
    Trade Feedback
    0 (0%)
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    AFAIK, the only real difference between SendMessage() and PostMessage() is that PostMessage is asynchronous and SendMessage is synchronous. Have you tried keybd_event() or SendInput()?

  3. #18
    xzidez's Avatar Member
    Reputation
    12
    Join Date
    Dec 2007
    Posts
    136
    Thanks G/R
    1/0
    Trade Feedback
    0 (0%)
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Originally Posted by schifers View Post
    When I start WoW process using the class Process from the .NET framework, I have an attribute in this class named MainWindowHandle. I can handle the window with this pointer I guess. I don't think I need to use FindWindow.

    So, after the WoW process starts, I use WaitForInputIdle and I start to send messages through PostMessage. I tried using SendMessage with no success, so I stick with PostMessage. If I use FindWindow, will I have another result? Is it the same handle that I get through MainWindowHandle?
    Code:
    [DllImport("user32.dll", SetLastError = true)]
    static extern int FindWindow(string lpClassName, string lpWindowName);
    
    [DllImport("user32.dll", CharSet = CharSet.Auto)]
    public static extern int SendMessage(int hWnd, int msg, int wParam, int lParam);
    
    private const int WM_KEYDOWN = 0x100;
    private const int WM_KEYUP = 0x101;
    and then use

    Code:
    int hWnd = FindWindow(null, "World of Warcraft");
    SendMessage(hWnd, WM_KEYDOWN, (int)Keys.J, 0);
    SendMessage(hWnd, WM_KEYUP, (int)Keys.J, 0);
    That FindWindow is really ugly. However I just tried this code so it should work. If the hWnd you get here is the same hWnd you have in your MainWindowHandle it should work just aswel with that one :P

  4. #19
    schifers's Avatar Member
    Reputation
    2
    Join Date
    Sep 2008
    Posts
    17
    Thanks G/R
    0/1
    Trade Feedback
    0 (0%)
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Originally Posted by RiotInferno View Post
    AFAIK, the only real difference between SendMessage() and PostMessage() is that PostMessage is asynchronous and SendMessage is synchronous. Have you tried keybd_event() or SendInput()?
    I didn't, because you need to have the focus on the window. I'm starting to program a multi-box bot, so I can't depend on that limitation. I need to send keys to the background windows too.

    Originally Posted by xzidez View Post
    That FindWindow is really ugly. However I just tried this code so it should work. If the hWnd you get here is the same hWnd you have in your MainWindowHandle it should work just aswel with that one :P
    It's the same handle, I just made a test. When I use FindWindow, it brings the same window handle if I use the MainWindowHandle from the Process class from .NET framework.

    Then I tried again to use SendMessage and one funny thing just happened. I sent some keys as I was typing my username. Between these keypresses, I made a random sleep from 0-100 ms. I made it just to simulate the lag we have between the key presses that human beings normally have. My window didn't receive the chars when I used SendMessage, but after the username, I sent a "\t" (VK_TAB), and the cursor changed from the username box to the password box. Then I sent the password and no success again, the chars didn't appeared as dots in the password field, but just after the password, I sent the char "\r" (VK_RETURN) and the program received it and it tried to login. So, the WoW main window got the tab and the return, but it didn't get the chars from username and password. I still stick with PostMessage.

    -----------------

    I MADE IT!!!

    I was able to send the "#" key to WoW login window using the WM_CHAR message and sending AscII code in the third parameter.

    Code:
    PostMessage(hWnd, (Int32)WM_CHAR, key, IntPtr.Zero);
    Thanks everybody... Next step I will try to choose one of the chars in the chars list. Cya all!!!
    Last edited by schifers; 10-07-2009 at 08:42 AM.

  5. Thanks LogicWin (1 members gave Thanks to schifers for this useful post)
  6. #20
    lanman92's Avatar Active Member
    Reputation
    50
    Join Date
    Mar 2007
    Posts
    1,033
    Thanks G/R
    0/1
    Trade Feedback
    0 (0%)
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Here you go.

    Code:
    static class Messaging
        {
            #region Imports
            [return: MarshalAs(UnmanagedType.Bool)]
            [DllImport("user32.dll", SetLastError = true)]
            private static extern bool PostMessage(IntPtr hWnd, uint Msg, IntPtr wParam,
               IntPtr lParam);
            #endregion
    
            private static bool PostMessageSafe(IntPtr hWnd, uint msg, IntPtr wParam, IntPtr lParam)
            {
                bool returnValue = PostMessage(hWnd, msg, wParam, lParam);
                if (!returnValue)
                {
                    return false;
                }
    
                return true;
            }
    
            public static bool SendKey(char key, IntPtr hWnd)
            {
                PostMessageSafe(hWnd, (uint)WM.WM_Keydown, (IntPtr)key, IntPtr.Zero);
                PostMessageSafe(hWnd, (uint)WM.WM_Keyup, (IntPtr)key, IntPtr.Zero);
    
                return true;
            }
    
            public static bool SendKey(VK key, bool upordown, IntPtr hWnd)
            {
                if (upordown)
                    return PostMessageSafe(hWnd, (uint)WM.WM_Keydown, (IntPtr)key, IntPtr.Zero);
                else
                    return PostMessageSafe(hWnd, (uint)WM.WM_Keyup, (IntPtr)key, IntPtr.Zero);
            }
    
            public static bool SendString(string message, IntPtr hWnd)
            {
                try
                {
                    char[] keys = message.ToCharArray();
                    foreach (char c in keys)
                    {
                        SendKey(c, hWnd);
                    }
                }
                catch (Exception)
                { return false; }
    
                return true;
            }
    
            private enum WM
            {
                WM_Keydown = 0x100,
                WM_Keyup = 0x101,
                WM_Char = 0x102
            }
    
            public enum VK
            {
                VK_LEFT = 0x25,
                VK_RIGHT = 0x27,
                VK_UP = 0x26,
                VK_DOWN = 0x28
            }
        }
    Have some basic VK codes in there since this was mainly for movement.

  7. #21
    RiotInferno's Avatar Member
    Reputation
    4
    Join Date
    Aug 2009
    Posts
    10
    Thanks G/R
    0/0
    Trade Feedback
    0 (0%)
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Originally Posted by schifers View Post

    I MADE IT!!!

    I was able to send the "#" key to WoW login window using the WM_CHAR message and sending AscII code in the third parameter.

    Code:
    PostMessage(hWnd, (Int32)WM_CHAR, key, IntPtr.Zero);
    Thanks everybody... Next step I will try to choose one of the chars in the chars list. Cya all!!!
    Glad to see it worked out!

Page 2 of 2 FirstFirst 12

Similar Threads

  1. Problem with WPE
    By weedlord in forum World of Warcraft General
    Replies: 0
    Last Post: 08-14-2006, 03:35 AM
  2. Problem with BWH 1.11.2
    By gwl15 in forum World of Warcraft General
    Replies: 3
    Last Post: 08-11-2006, 05:37 PM
  3. Problem with CE.
    By Eldretch in forum World of Warcraft General
    Replies: 1
    Last Post: 08-08-2006, 06:49 PM
  4. I have problem with BHW 3.0
    By sunrize1 in forum World of Warcraft General
    Replies: 1
    Last Post: 07-17-2006, 08:49 AM
All times are GMT -5. The time now is 02:56 PM. Powered by vBulletin® Version 4.2.3
Copyright © 2025 vBulletin Solutions, Inc. All rights reserved. User Alert System provided by Advanced User Tagging (Pro) - vBulletin Mods & Addons Copyright © 2025 DragonByte Technologies Ltd.
Google Authenticator verification provided by Two-Factor Authentication (Free) - vBulletin Mods & Addons Copyright © 2025 DragonByte Technologies Ltd.
Digital Point modules: Sphinx-based search