[Help][C#] Sending keystrokes to WoW menu

User Tag List

Results 1 to 14 of 14
  1. #1
    wowhackz0r's Avatar Member
    Reputation
    3
    Join Date
    Jun 2008
    Posts
    31
    Thanks G/R
    0/0
    Trade Feedback
    0 (0%)
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    [Help][C#] Sending keystrokes to WoW

    I am trying to send keystrokes to WoW, but for some reason i am failing. When modified, the code works correctly in other programs, but will not work with WoW. Here is the code i am using:

    Code:
        static void Main()
        {
            Process[] procs = Process.GetProcessesByName("Wow");
                
           foreach (Process proc in procs)
          {        
                if (proc.MainWindowTitle == "World of Warcraft")
                {
                  
                   IntPtr hWnd = FindWindowEx(proc.MainWindowHandle, IntPtr.Zero, "GxWindowClassD3d", null);
                              
                   
                    string s = "hello";
                    for (int i = 0; i < s.Length; i++)
                    {
                     
                        PostMessage(hWnd, WM_KEYDOWN, VkKeyScan(s[i]), 0);
    
                    }
    
                   
                    break;
                }
            }
                    
        }
    I found the window class using Spy++, did I do something wrong?

    Thanks for the help

    [Help][C#] Sending keystrokes to WoW
  2. #2
    snigelmannen's Avatar Member
    Reputation
    27
    Join Date
    Jul 2007
    Posts
    318
    Thanks G/R
    0/0
    Trade Feedback
    0 (0%)
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Well keys can be sent with auto it and stuff, but if you are working with wow, use BlackMagic and write to the process instead.
    " Spy sappin mah sentry! "

  3. #3
    wowhackz0r's Avatar Member
    Reputation
    3
    Join Date
    Jun 2008
    Posts
    31
    Thanks G/R
    0/0
    Trade Feedback
    0 (0%)
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Originally Posted by snigelmannen View Post
    Well keys can be sent with auto it and stuff, but if you are working with wow, use BlackMagic and write to the process instead.
    I forgot to mention that the goal is to NOT write memory at all.

  4. #4
    snigelmannen's Avatar Member
    Reputation
    27
    Join Date
    Jul 2007
    Posts
    318
    Thanks G/R
    0/0
    Trade Feedback
    0 (0%)
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    You will find most of the help at MSDN if you are using C#, if you want to go with a passive bot why not go with auto it? I'm actually going over to begin with simple writetoprocess stuff for my own stuff as soon as i learn exceptions and more about how to use the language etc

    But SendKeys Class (System.Windows.Forms)

    try that
    " Spy sappin mah sentry! "

  5. #5
    wowhackz0r's Avatar Member
    Reputation
    3
    Join Date
    Jun 2008
    Posts
    31
    Thanks G/R
    0/0
    Trade Feedback
    0 (0%)
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Originally Posted by snigelmannen View Post
    You will find most of the help at MSDN if you are using C#, if you want to go with a passive bot why not go with auto it? I'm actually going over to begin with simple writetoprocess stuff for my own stuff as soon as i learn exceptions and more about how to use the language etc

    But SendKeys Class (System.Windows.Forms)

    try that
    i don't like to really use others peoples work, i want more control over the bot, and i know c# (quite similar to java, which i know very well) whereas i don't know how to program in autoit, so since java isn't the best solution for a wow bot, i figured c# would work well.
    thanks for the info and link

    can anybody else see a problem in the code?

  6. #6
    ~Unknown~'s Avatar Contributor
    Reputation
    193
    Join Date
    Jan 2009
    Posts
    211
    Thanks G/R
    0/5
    Trade Feedback
    0 (0%)
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I know you said you don't like using other's code, but BlackMagic makes programming in C# with wow a whole lot easier. Even WhiteMagic too. Also, not completely sure where your code fails but here is how I've done it. Extra nasty code slapped in there for emphasis on whats being used. See if you can compare the differences.

    Code:
    public class SendKey
        {
            [DllImport("user32.dll", SetLastError = true)]
            static extern bool PostMessage(IntPtr hWnd, uint Msg, int wParam, int lParam);
            [DllImport("user32.dll", SetLastError = true)]
            static extern IntPtr FindWindow(string lpClassName, string lpWindowName);
    
            private const Int32 WM_KEYDOWN = 0x0100;
            private const Int32 WM_KEYUP = 0x0101;
    
            public void Send(int Key)
            {
                IntPtr Handle = FindWindow(null, "World of Warcraft");
                PostMessage(Handle, WM_KEYDOWN, Key, 0);
                PostMessage(Handle, WM_KEYUP, Key, 0);
            }
        }

    I would also recommend this thread:
    http://www.mmowned.com/forums/wow-me...ml#post1700083
    Last edited by ~Unknown~; 12-20-2009 at 03:37 AM.

  7. #7
    wowhackz0r's Avatar Member
    Reputation
    3
    Join Date
    Jun 2008
    Posts
    31
    Thanks G/R
    0/0
    Trade Feedback
    0 (0%)
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Originally Posted by ~Unknown~ View Post
    I know you said you don't like using other's code, but BlackMagic makes programming in C# with wow a whole lot easier. Even WhiteMagic too. Also, not completely sure where your code fails but here is how I've done it. Extra nasty code slapped in there for emphasis on whats being used. See if you can compare the differences.

    Code:
    public class SendKey
        {
            [DllImport("user32.dll", SetLastError = true)]
            static extern bool PostMessage(IntPtr hWnd, uint Msg, int wParam, int lParam);
            [DllImport("user32.dll", SetLastError = true)]
            static extern IntPtr FindWindow(string lpClassName, string lpWindowName);
    
            private const Int32 WM_KEYDOWN = 0x0100;
            private const Int32 WM_KEYUP = 0x0101;
    
            public void Send(int Key)
            {
                IntPtr Handle = FindWindow(null, "World of Warcraft");
                PostMessage(Handle, WM_KEYDOWN, Key, 0);
                PostMessage(Handle, WM_KEYUP, Key, 0);
            }
        }

    I would also recommend this thread:
    http://www.mmowned.com/forums/wow-me...ml#post1700083
    thank you for your help. i figured out my problem and i am still kicking my self for it. i wasn't running visual studio as administrator (**** you windows 7)

  8. #8
    Seifer's Avatar Site Donator
    Reputation
    129
    Join Date
    Apr 2007
    Posts
    270
    Thanks G/R
    1/0
    Trade Feedback
    0 (0%)
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Even though you don't want to be using other people their code, Shynd has made a very neat PostMessage class, which I recommend for this sort of stuff.

    http://www.shynd.com/code/PostMessage.cs

  9. #9
    Bananenbrot's Avatar Contributor
    Reputation
    153
    Join Date
    Nov 2009
    Posts
    384
    Thanks G/R
    1/3
    Trade Feedback
    0 (0%)
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    And you don't need to copy/paste all VKey Values for the WPARAM... an build-in enum will do the work for you:
    Code:
    using System;
    using System.ComponentModel;
    using System.Runtime.InteropServices;
    using System.Windows.Forms;
    
    namespace Windows.Interop
    {
        static class KeySim
        {
            #region P/Invoke
            private const uint WM_KEYDOWN = 0x100,
                WM_KEYUP = 0x101;
    
            [DllImport("user32", EntryPoint = "PostMessage", SetLastError = true)]
            [return: MarshalAs(UnmanagedType.Bool)]
            private extern static bool InternalPostMessage(IntPtr hWnd, uint Msg, IntPtr wParam, IntPtr lParam);
            #endregion
    
            public static void KeyDown(Keys keyDown)
            {
                if (!InternalPostMessage(ObjectManager.MemReader.MainWindowHandle,  // Insert your WowProcessHandle!
                    WM_KEYDOWN,
                    new IntPtr(IntPtr.Size == 4 ? (int)keyDown : (long)keyDown), // WPARAM is x64/x86 dependant, therefore cast from long/int to IntPtr
                    IntPtr.Zero)) throw new Win32Exception(Marshal.GetLastWin32Error());
            }
    
            public static void KeyUp(Keys keyUp)
            {
                if (!InternalPostMessage(ObjectManager.MemReader.MainWindowHandle,
                    WM_KEYUP,
                    new IntPtr(IntPtr.Size == 4 ? (int)keyUp : (long)keyUp),
                    IntPtr.Zero)) throw new Win32Exception(Marshal.GetLastWin32Error());
            }
    
            public static void ReleaseArrowKeys()
            {
                KeyUp(Keys.Up);
                KeyUp(Keys.Down);
                KeyUp(Keys.Left);
                KeyUp(Keys.Right);
            }
        }
    }
    is just how i've done it. This uses the Keys-enum in System.Windows.Forms.
    Last edited by Bananenbrot; 12-22-2009 at 03:06 PM.

  10. #10
    Learner's Avatar Member
    Reputation
    1
    Join Date
    May 2007
    Posts
    5
    Thanks G/R
    0/0
    Trade Feedback
    0 (0%)
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    What is the difference between InternalPostMessage and PostMessage? I found no documentation on the InternalPostMessage in user32

  11. #11
    Seifer's Avatar Site Donator
    Reputation
    129
    Join Date
    Apr 2007
    Posts
    270
    Thanks G/R
    1/0
    Trade Feedback
    0 (0%)
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Originally Posted by snigelmannen View Post
    Well keys can be sent with auto it and stuff, but if you are working with wow, use BlackMagic and write to the process instead.
    Also, this is _not_ the way to go.

  12. #12
    labelhinder's Avatar Private
    Reputation
    1
    Join Date
    Mar 2010
    Posts
    1
    Thanks G/R
    0/0
    Trade Feedback
    0 (0%)
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Originally Posted by Learner View Post
    What is the difference between InternalPostMessage and PostMessage? I found no documentation on the InternalPostMessage in user32
    *B*

    Learner, InternalPostMessage will in the end call native dll user32 function PostMessage (same as on msdn), only its name in c# will be InternalPostMessage.

    Look at definition for import:

    user32.dll, entrypoint = "PostMessage"

    [DllImport("user32", EntryPoint = "PostMessage", SetLastError = true)]
    [return: MarshalAs(UnmanagedType.Bool)]
    private extern static bool InternalPostMessage(IntPtr hWnd, uint Msg, IntPtr wParam, IntPtr lParam);


    Hope it will help at least some1

  13. #13
    SilentWarrior's Avatar Member
    Reputation
    7
    Join Date
    Sep 2008
    Posts
    52
    Thanks G/R
    0/0
    Trade Feedback
    0 (0%)
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Pretty simple :

    PostMessage(proc.MainWindowHandle, WM_KEYDOWN, VkKeyScan(s[i]), 0);
    Thread.Sleep(50);
    PostMessage(proc.MainWindowHandle, WM_KEYUP, VkKeyScan(s[i]), 0);

    Done, no need to complicate. Now, if you then want to convert text to key... thats harder...

  14. #14
    bicideoo's Avatar Banned
    Reputation
    1
    Join Date
    Nov 2010
    Posts
    3
    Thanks G/R
    0/0
    Trade Feedback
    0 (0%)
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    That, obviously, is a best-case Aion Leveling. It

    won't be so easy every time. If you don't see an improvement after you've planted the
    WOW Gold, you'll have a decision to make. You can leave it

    be, accepting that the player will not improve further and making decisions about his participation

    accordingly. You can faze him out of Aion Gold raids, if

    necessary, and only take the steps below when and if he approaches

    WOW Power Leveling about why he isn't being included.

    Or, you can decide to be more aggressive: to get real and
    hash it Buy WOW Gold.

Similar Threads

  1. need help with playing song on wow
    By tathar26 in forum World of Warcraft Emulator Servers
    Replies: 1
    Last Post: 07-16-2008, 08:42 AM
  2. Sending keystrokes to AoC window in background
    By Ghazban in forum Age of Conan Exploits|Hacks
    Replies: 1
    Last Post: 07-01-2008, 04:18 AM
  3. Need help from a pro (hack) wow player =D
    By Kzaf in forum World of Warcraft Emulator Servers
    Replies: 4
    Last Post: 03-09-2008, 04:17 PM
  4. Need a little help for free time of WoW =(
    By Pwnnned in forum World of Warcraft General
    Replies: 3
    Last Post: 06-09-2007, 11:40 AM
  5. Can someone help me get onto a WoW private server?
    By hyacary in forum Gaming Chat
    Replies: 1
    Last Post: 01-25-2007, 03:14 PM
All times are GMT -5. The time now is 02:41 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