Sending Keys in C# to GW2 menu

User Tag List

Results 1 to 9 of 9
  1. #1
    RazorDreamz's Avatar Private
    Reputation
    1
    Join Date
    Feb 2012
    Posts
    5
    Thanks G/R
    0/0
    Trade Feedback
    0 (0%)
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Sending Keys in C# to GW2

    I'm working on a bot for GW2 using C#. I can detect pixels, and use the mouse to move and click etc, but for some reason sending keys isn't working for me.

    I've tried:

    Code:
    SendKeys.SendWait("1");  // does nothing except pop the menu for some reason.
    Also:

    Code:
    BotControl.SendMessage(win, WM_KEYDOWN, ((IntPtr) Keys.Oem1), IntPtr.Zero);
    Seems to do nothing that I can tell.

    Code:
    BotControl.PostMessage(win, BotControl.WM_KEYDOWN, ((IntPtr) Keys.Oem1),IntPtr.Zero);
    Does nothing, but if I select the chat window it drops ";" in chat instead of "1".

    Also tried the Virtual Keyboard:

    Code:
    [DllImport("user32.dll")]
                private static extern uint keybd_event(byte bVk, byte bScan, int dwFlags, int dwExtraInfo);
    
                public static void KeyDown(Keys key)
                {
                    keybd_event((byte) key, 0, 0, 0);
                }
    
                public static void KeyUp(Keys key)
                {
                    keybd_event((byte) key, 0, 0x0002, 0);
                }
    doing
    Code:
    KeyDown(Keys.Oem1);
    KeyUp(Keys.Oem1);
    And it also does nothing, but if I select the chat window it prints ";" again.

    Any ideas what could be going wrong? Did this for WOW, EVE and SWTOR without issue.

    These ads disappear when you log in.

  2. #2
    spawnfestis's Avatar Contributor
    Reputation
    85
    Join Date
    May 2009
    Posts
    261
    Thanks G/R
    0/0
    Trade Feedback
    0 (0%)
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Try posting a keyboard message instead using the PostMessage() API, you can look it up here at MSDN

  3. #3
    saddened's Avatar Member
    Reputation
    1
    Join Date
    Apr 2009
    Posts
    4
    Thanks G/R
    0/0
    Trade Feedback
    0 (0%)
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    GW2 uses DirectInput to receive keyboard/mouse events, window messages/events won't work.

    SendInput function (SendInput)

  4. #4
    xtrmxtrm's Avatar Member
    Reputation
    1
    Join Date
    Apr 2011
    Posts
    25
    Thanks G/R
    0/0
    Trade Feedback
    0 (0%)
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    In autoit there is a ControlSendKey function which does what you want. You will need to do the same as that method.
    1. Focus in the windows of GW2 and set it active.
    2. Send Control Keys to the focused active window of GW2.

  5. #5
    Maddin1803's Avatar Member
    Reputation
    25
    Join Date
    Mar 2012
    Posts
    40
    Thanks G/R
    0/0
    Trade Feedback
    0 (0%)
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    @saddened
    Are you absolutly sure ?
    I thought you can use postmessage, with the right parms.

  6. #6
    Arakkoa's Avatar Member
    Reputation
    1
    Join Date
    Sep 2007
    Posts
    34
    Thanks G/R
    0/0
    Trade Feedback
    0 (0%)
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    keybd_event function

    This is also a way, I'm sure pinvoke.net or something has the C# stuff you need to use this.

  7. #7
    MrUnreal's Avatar Sergeant
    Reputation
    19
    Join Date
    May 2012
    Posts
    46
    Thanks G/R
    0/0
    Trade Feedback
    0 (0%)
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    PostMsg works just fine

  8. #8
    viperbot's Avatar Contributor
    Reputation
    103
    Join Date
    Jan 2012
    Posts
    599
    Thanks G/R
    2/53
    Trade Feedback
    0 (0%)
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    keybd_event works fine, just make sure the game has the focus.

  9. #9
    Xelper's Avatar ★ Elder ★
    Reputation
    1024
    Join Date
    Mar 2007
    Posts
    860
    Thanks G/R
    0/8
    Trade Feedback
    0 (0%)
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Call Example() when GW2 has focus. If you are in windowed mode it doesn't need to have focus. You need to have the proper wParam and lParam. You can google them for a list.

    Code:
            [DllImport("User32.Dll")]
            public static extern Int32 PostMessage(int hWnd, int msg, int wParam, int lParam);
    
    
            [DllImport("user32.dll")]
            static extern IntPtr GetForegroundWindow();
    
    
            ///summary>
            /// Virtual Messages
            /// </summary>
            public enum WMessages : int
            {
                WM_LBUTTONDOWN = 0x201, //Left mousebutton down
                WM_LBUTTONUP = 0x202,  //Left mousebutton up
                WM_LBUTTONDBLCLK = 0x203, //Left mousebutton doubleclick
                WM_RBUTTONDOWN = 0x204, //Right mousebutton down
                WM_RBUTTONUP = 0x205,   //Right mousebutton up
                WM_RBUTTONDBLCLK = 0x206, //Right mousebutton doubleclick
                WM_KEYDOWN = 0x100,  //Key down
                WM_KEYUP = 0x101,   //Key up
            }
    
    
            public static void PostMessage_PressKeyDown(int hWnd, int Key, int lParam)
            {
                PostMessage(hWnd, (int)WMessages.WM_KEYDOWN, Key, lParam);
            }
            public static void PostMessage_PressKeyUp(int hWnd, int Key, int lParam)
            {
                PostMessage(hWnd, (int)WMessages.WM_KEYUP, Key, lParam);
            }
    
    
    
    
    	public static void Example()
    	{
    
    
    		int VK_2 = (int)0x32;
    		int VK_2_lParam = 0x30001;
    		System.Threading.Thread.Sleep(3000); //This is just so you have enough time to get back to the proper foreground window that you wanna send the 2s to...this can be avoided by using a saved hWnd instead of GetForgroundWindow()
    		cSendInput.PostMessage_PressKeyDown(GetForegroundWindow(), VK_2, VK_2_lParam);
    		System.Threading.Thread.Sleep(1000);
    		cSendInput.PostMessage_PressKeyUp(GetForegroundWindow(), VK_2, VK_2_lParam);
    	}

Similar Threads

  1. c# Send key to Gw2 to move characters
    By Ancitique in forum Guild Wars 2
    Replies: 2
    Last Post: 12-28-2018, 01:58 AM
  2. Send keys to Aion in C#
    By debos in forum Programming
    Replies: 2
    Last Post: 11-19-2009, 09:56 AM
  3. Sending Keys
    By EmiloZ in forum Programming
    Replies: 5
    Last Post: 10-12-2008, 05:40 AM
  4. [Question] Send Keys to Window
    By TuFF in forum Programming
    Replies: 4
    Last Post: 10-09-2008, 05:55 PM
  5. Freebie method for sending keys to multiple WoW windows
    By tomit12 in forum World of Warcraft Guides
    Replies: 6
    Last Post: 03-03-2008, 10:49 AM
All times are GMT -5. The time now is 03:22 PM. Powered by vBulletin® Version 4.2.3
Copyright © 2020 vBulletin Solutions, Inc. All rights reserved. User Alert System provided by Advanced User Tagging (Pro) - vBulletin Mods & Addons Copyright © 2020 DragonByte Technologies Ltd.
Digital Point modules: Sphinx-based search