Results 1 to 10 of 223

Thread: [WIP] GuiltySpark

Threaded View

Previous Post Previous Post   Next Post Next Post
  1. #11
    chilango Con's Avatar
    Join Date
    Aug 2006
    Location
    Victoria, BC, Canada
    Posts
    8,397

    Re: [WIP] HaloBot

    Good news, I found the solution. Limited suggested I use SendInput instead.
    you'll need these

    Code:
            #region constants
            const int INPUT_MOUSE = 0;
            const int INPUT_KEYBOARD = 1;
            const int INPUT_HARDWARE = 2;
            const uint KEYEVENTF_EXTENDEDKEY = 0x0001;
            const uint KEYEVENTF_KEYUP = 0x0002;
            const uint KEYEVENTF_UNICODE = 0x0004;
            const uint KEYEVENTF_SCANCODE = 0x0008;
            const uint XBUTTON1 = 0x0001;
            const uint XBUTTON2 = 0x0002;
            const uint MOUSEEVENTF_MOVE = 0x0001;
            const uint MOUSEEVENTF_LEFTDOWN = 0x0002;
            const uint MOUSEEVENTF_LEFTUP = 0x0004;
            const uint MOUSEEVENTF_RIGHTDOWN = 0x0008;
            const uint MOUSEEVENTF_RIGHTUP = 0x0010;
            const uint MOUSEEVENTF_MIDDLEDOWN = 0x0020;
            const uint MOUSEEVENTF_MIDDLEUP = 0x0040;
            const uint MOUSEEVENTF_XDOWN = 0x0080;
            const uint MOUSEEVENTF_XUP = 0x0100;
            const uint MOUSEEVENTF_WHEEL = 0x0800;
            const uint MOUSEEVENTF_VIRTUALDESK = 0x4000;
            const uint MOUSEEVENTF_ABSOLUTE = 0x8000;
            #endregion
    
            #region structures
            struct MOUSEINPUT
            {
                public int dx;
                public int dy;
                public uint mouseData;
                public uint dwFlags;
                public uint time;
                public IntPtr dwExtraInfo;
            }
    
            struct KEYBDINPUT
            {
                public ushort wVk;
                public ushort wScan;
                public uint dwFlags;
                public uint time;
                public IntPtr dwExtraInfo;
            }
    
            struct HARDWAREINPUT
            {
                public int uMsg;
                public short wParamL;
                public short wParamH;
            }
    
            [StructLayout(LayoutKind.Explicit)]
            struct MOUSEKEYBDHARDWAREINPUT
            {
                [FieldOffset(0)]
                public MOUSEINPUT mi;
    
                [FieldOffset(0)]
                public KEYBDINPUT ki;
    
                [FieldOffset(0)]
                public HARDWAREINPUT hi;
            }
    
            struct INPUT
            {
                public int type;
                public MOUSEKEYBDHARDWAREINPUT mkhi;
            }
            #endregion
    
            [DllImport("user32.dll", SetLastError = true)]
            static extern uint SendInput(uint nInputs, ref INPUT pInputs, int cbSize);


    Code:
                        INPUT structInput = new INPUT();
                        structInput.mkhi.ki.wScan = (ushort)0x11;
                        structInput.mkhi.ki.time = 0;
                        structInput.mkhi.ki.dwFlags = KEYEVENTF_SCANCODE;
                        structInput.mkhi.ki.wVk = 0;
                        structInput.type = INPUT_KEYBOARD;
                        SendInput(1, ref structInput, Marshal.SizeOf(new INPUT()));
    Here's a list of key codes.


    EDIT: success!
    HaloBot has just walked from one side of bloodgulch to the other following the paths perfectly. You can even look around while it does this; it calculates the right combination of WASD to use based on the angle you're looking and where the goal is.
    Last edited by Con; May 12th, 2010 at 10:58 PM.
    Reply With Quote

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Tags for this Thread

Bookmarks

Posting Permissions

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