Problem with Keys menu

User Tag List

Page 1 of 2 12 LastLast
Results 1 to 15 of 21
  1. #1
    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)

    Problem with Keys

    I'm programming my first steps in automating WoW and some things I have done are:

    1) I started the WoW process using System.Diagnostics.Process;

    Process proc = new Process();
    proc.StartInfo.FileName = path + filename;
    proc.Start();
    proc.WaitForInputIdle();

    2) I changed the WoW's window style with no borders:

    IntPtr ws = GetWindowLongPtr(this.handle, (IntPtr)GWL.GWL_STYLE);
    SetWindowLongPtr(this.handle, (IntPtr)GWL.GWL_STYLE, (IntPtr)(((int)ws) & ~(WS_THICKFRAME | WS_CAPTION)));

    3) I changed the WoW's window position and size:

    RECT rect;
    GetWindowRect(this.handle, out rect);
    rect.left = this.posX;
    rect.top = this.posY;
    rect.width = this.width;
    rect.height = this.height;
    MoveWindow((IntPtr)hWnd, (IntPtr)rect.left, (IntPtr)rect.top, (IntPtr)rect.width, (IntPtr)rect.height, true);

    4) I started to send keystrokes for my window:

    The problem start here...

    I was able to send keystrokes using PostMessage.

    I tried to use SendMessage to WoW main window and it didn't work.

    I was trying to auto fill the login text box simulating keystrokes using SendMessage.

    When I changed to PostMessage, the window started to receive the messages and letters appeared in the text box.

    I was able to send lower case letters and upper case letters using these commands:

    for lowercase:

    PostMessage(hWnd, (Int32)WM_KEYDOWN, key, IntPtr.Zero);

    for uppercase:

    PostMessage(hWnd, (Int32)WM_KEYDOWN, VK_SHIFT, (IntPtr)0x1000000);
    PostMessage(hWnd, (Int32)WM_CHAR, VK_S, IntPtr.Zero);
    PostMessage(hWnd, (Int32)WM_KEYUP, VK_SHIFT, (IntPtr)0x1000000);

    What I am trying to do now, it is to send special symbols like "!", "@", "#", etc...

    On my keyboard, for example, my "#" key is above the number 3 key.

    I tried to send WM_KEYDOWN and VK_SHIFT to the window, then I sent a WM_CHAR and VK_3 and last I sent a WM_KEYUP and VK_SHIFT again.

    It didn't work. When I saw the result, it was showing 3 instead of "#" in the textbox.

    Can somebody tell me what am I doing wrong? How can I send these symbols to my window? Last one, how can I send keystrokes safely?
    Last edited by schifers; 10-02-2009 at 12:22 PM.

    Problem with Keys
  2. #2
    Neverhaven's Avatar Member
    Reputation
    12
    Join Date
    Sep 2009
    Posts
    25
    Thanks G/R
    0/0
    Trade Feedback
    0 (0%)
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Any reason you're not using SendInput?

  3. #3
    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 Neverhaven View Post
    Any reason you're not using SendInput?
    No, just because I came from C++ and I'm used to use SendMessage and PostMessage.

    I read somewhere that SendMessage would be safer than SendKeys.

    I didn't read anything about SendInput, but I will research.

    Can I send those symbols using SendInput? Is it safer?

  4. #4
    EmilyStrange's Avatar Active Member
    Reputation
    34
    Join Date
    Jul 2009
    Posts
    125
    Thanks G/R
    0/0
    Trade Feedback
    0 (0%)
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Recommendations

    SendInput only sends key presses to the window currently in focus. Personally I would stick with PostMessage or SendMessage depending your preference and needs.

    Many of the keys you are attempting to send are OEM keys, you will need to look those up in the MSDN documentation. My recommendation is to download HotKeyNet because it has a little window off to the side that prints out the key press (and OEM code and name) when you press any key on the keyboard. There are other utilities that do this too, but that one is good for experimentation if all you want to do is simple scripting of Warcraft such as sending keys, removing window borders, etc.

    Also, may I recommend you download and make use of ManagedWinAPI? It is a very fine OpenSource project that does a lot of the messy WIN32 code for you such as handling hotkeys, window positions, window styles, without having to declare your own WIN32 API calls.

  5. #5
    Neverhaven's Avatar Member
    Reputation
    12
    Join Date
    Sep 2009
    Posts
    25
    Thanks G/R
    0/0
    Trade Feedback
    0 (0%)
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Right, i forgot SendInput only works for the window in focus. If you still want to give it a go and try and do your own thing, then here's something to work from. I use it in my fishing bot atm, and it's working perfectly.

    Code:
    class SendInputs
    {
        [DllImport("user32.dll")]
        private static extern int SendMessage(IntPtr hWnd, UInt32 Msg, Int32 wParam, Int32 lParam);
        [DllImport("user32.dll")]
        private static extern int SendMessage(IntPtr hWnd, UInt32 Msg, Int32 wParam, IntPtr lParam);
        [DllImport("user32.dll")]
        private static extern int SendMessage(IntPtr hWnd, UInt32 Msg, IntPtr wParam, Int32 lParam);
        [DllImport("user32.dll")]
        private static extern int SendMessage(IntPtr hWnd, UInt32 Msg, IntPtr wParam, IntPtr lParam);
    
        public class VK
        {
            public const Int32 ENTER = 0x0D;
            public const Int32 LEFT = 0x25;
            public const Int32 UP = 0x26;
            public const Int32 RIGHT = 0x27;
            public const Int32 DOWN = 0x28;
            public const Int32 F2 = 0x71;
        }
        public class WM
        {
            public const UInt32 BUTTONDOWN = 0x0100;
            public const UInt32 BUTTONUP = 0x0101;
        }
        public static void ButtonDown(Process Process, Int32 Key)
        {
            SendMessage(Process.MainWindowHandle, WM.BUTTONDOWN, Key, IntPtr.Zero);
        }
        public static void ButtonUp(Process Process, Int32 Key)
        {
            SendMessage(Process.MainWindowHandle, WM.BUTTONUP, Key, IntPtr.Zero);
        }
        public static void ButtonType(Process Process, Int32 Key)
        {
            SendMessage(Process.MainWindowHandle, WM.BUTTONDOWN, Key, IntPtr.Zero);
            SendMessage(Process.MainWindowHandle, WM.BUTTONUP, Key, IntPtr.Zero);
        }
    }
    And here's the constants.

    It's pretty incomplete, but it works like a charm.

    EDIT:
    Forgot, and here's how i think you should do your shift thing.
    Code:
    SendInputs.ButtonDown(YourProcess, ShiftVirtualKey)
    SendInputs.ButtonType(YourProcess, SomeVirualKey)
    SendInputs.ButtonUp(YourProcess, ShiftVirtualKey)
    Untested tho.
    Last edited by Neverhaven; 10-02-2009 at 03:28 PM.

  6. #6
    Apoc's Avatar Angry Penguin
    Reputation
    1387
    Join Date
    Jan 2008
    Posts
    2,750
    Thanks G/R
    0/12
    Trade Feedback
    0 (0%)
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    SendInput is wrapped by 'SendKeys' in .NET. (Just use that if you don't care about WoW being focused)

    Also; use PostMessageA instead of SendMessage.

    Lastly... stop doing 2x KeyDown calls. Just do 1 with proper params.

  7. #7
    Cypher's Avatar Kynox's Sister's Pimp
    Reputation
    1358
    Join Date
    Apr 2006
    Posts
    5,368
    Thanks G/R
    0/6
    Trade Feedback
    0 (0%)
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Originally Posted by Apoc View Post
    SendInput is wrapped by 'SendKeys' in .NET. (Just use that if you don't care about WoW being focused)

    Also; use PostMessageA instead of SendMessage.

    Lastly... stop doing 2x KeyDown calls. Just do 1 with proper params.
    Huh? He's doing one WM_KEYDOWN and one WM_CHAR. That's how input is normally generated for a window...

  8. #8
    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 EmilyStrange View Post
    Many of the keys you are attempting to send are OEM keys, you will need to look those up in the MSDN documentation.
    Ok, I tried to find the OEM code for the key "#". There is no such code. I downloaded HotKeyNet and tried to press the number 3 on my keyboard while I was holding the key SHIFT. HotKeyNet receives a WM_KEYDOWN of the key VK_SHIFT and then a WM_KEYDOWN of the key 3, code 51, which is the same of VK_3 = 0x33. If I send these both messages to the WoW main window, it still generates the number "3" instead of "#".

    How keyboards work with those keys? They are not OEM keys, I guess. I was imagining if it is the keyboard driver that handle these keys above the numbers in the keyboard. I tried to send the same keys to notepad and still no success. Notepad receives only the key "3".

    How do those dummy HID driver work? Is it the solution for this problem?

  9. #9
    Mr.Zunz's Avatar Contributor
    Reputation
    92
    Join Date
    Mar 2007
    Posts
    393
    Thanks G/R
    0/0
    Trade Feedback
    0 (0%)
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Code:
    [DllImport("user32.dll")]
            static extern byte VkKeyScan(char ch);
    You might want to check that out, dont know if it also works with shift usage but you could try.


  10. #10
    evil2's Avatar Active Member
    Reputation
    27
    Join Date
    Feb 2009
    Posts
    171
    Thanks G/R
    31/9
    Trade Feedback
    0 (0%)
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    const int VK_OEM_2 = 0xBF; // #

    PostMessage(hWnd, WM_KEYDOWN, VK_OEM_2, 0);
    PostMessage(hWnd, WM_KEYUP, VK_OEM_2, 0xC0000000);

  11. #11
    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)
    after a little bit of googling the accepted answer seems to be that PostMessage() doesn't update the shift state, regardless of if the shift key is sent or not. Most people, therefore, recommend keybd_event() or SendInput()

  12. #12
    suicidity's Avatar Contributor
    Reputation
    207
    Join Date
    Oct 2006
    Posts
    1,439
    Thanks G/R
    0/0
    Trade Feedback
    0 (0%)
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    You could try some of these; Note I'm writing this off hand so it may not be exact.

    Code:
    public void SendKeys(IntPtr Hwnd, string String)
    {
    	foreach (char Char in String)
    		PostMessage(Hwnd, WM_CHAR, Convert.ToInt32(Char), 0);
    }
    ...
    public void SendKey(IntPtr Hwnd, int Key, bool Shift, bool Control)
    {
    	byte[] State = new byte[256];
    	GetKeyboardState(State)
    
    	if (Shift)
    		State[VK_SHIFT] |= 0x80;
    	if (Control)
    		State[VK_CTRL] |= 0x80;
    	SetKeyboardState(State);
    
    	PostMessage(Hwnd, WM_KEYDOWN, Key, 0);
    	//PostMessage(Hwnd, WM_KEYUP, Key, 0xC0000000 + Sc);
    
    	State[VK_SHIFT] &= 0x00;
    	State[VK_CTRL] &= 0x00;
    	SetKeyboardState(State);
    }
    You can send any characters though with the string method, which I prefer ; You just have to create the string if need be.


  13. #13
    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)
    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");

  14. #14
    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 drevil2 View Post
    const int VK_OEM_2 = 0xBF; // #

    PostMessage(hWnd, WM_KEYDOWN, VK_OEM_2, 0);
    PostMessage(hWnd, WM_KEYUP, VK_OEM_2, 0xC0000000);
    I see... You have set bit 30 and 31 for the lparam of the WM_KEYUP message. So, I was not making it right, because the documentation says:

    30
    Specifies the previous key state. The value is always 1 for a WM_KEYUP message.
    31
    Specifies the transition state. The value is always 1 for a WM_KEYUP message.


    Ok, but I tried this code and I got another char, not the "#", which probably means that my OEM code is different from yours, right?

    Since I got a different character, I tried to find what can I make different to get the char I need. I'm trying to find out how to use bits 16-23, since they:

    16-23
    Specifies the scan code. The value depends on the OEM.

    Maybe the answer is here, using those bits in the lparam of the message.
    Last edited by schifers; 10-06-2009 at 06:39 AM.

  15. #15
    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 suicidity View Post
    You can send any characters though with the string method, which I prefer ; You just have to create the string if need be.
    Do you mean WM_COPYDATA message? Can you send a string to the WoW login window using WM_COPYDATA?

    I tried and I didn't succeded.

    I'm trying to send my username and password to my login window, so I can leave my computer on, and my bot would log in WoW and play at the time I say it to do it. Since my password has special chars like "#". I'm having problems to send those chars to the login window, and even to notepad, I'm not able to send those chars to notepad either, but I'm still trying.

Page 1 of 2 12 LastLast

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:01 AM. 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.
Digital Point modules: Sphinx-based search