Results 1 to 5 of 5

Thread: Need help with SendInput

  1. #1

    Thread Starter
    Lively Member
    Join Date
    Jul 2009
    Posts
    127

    Angry Need help with SendInput

    I’m trying to achieve mouse movements with SendInput.

    There is code that got from Pinvoke, http://www.pinvoke.net/default.aspx/user32.SendInput

    Code:
    <DllImport("user32.dll", SetLastError = True)> _
    Private Shared Function SendInput(ByVal nInputs As Integer, ByRef pInputs As InputLanguage,
    ByVal cbSize As Integer) As Integer
    End Function
    Public Class Form1
        Private Declare Function SendInput Lib "user32.dll" (ByVal cInputs As Integer, ByRef pInputs As INPUT, ByVal cbSize As Integer) As Integer
        Private Structure INPUT
            Dim dwType As Integer
            Dim mkhi As MOUSEKEYBDHARDWAREINPUT
        End Structure
    
        Private Structure KEYBDINPUT
            Public wVk As Short
            Public wScan As Short
            Public dwFlags As Integer
            Public time As Integer
            Public dwExtraInfo As IntPtr
        End Structure
    
        Private Structure HARDWAREINPUT
            Public uMsg As Integer
            Public wParamL As Short
            Public wParamH As Short
        End Structure
    
        <StructLayout(LayoutKind.Explicit)> _
    Private Structure MOUSEKEYBDHARDWAREINPUT
            <FieldOffset(0)> Public mi As MOUSEINPUT
            <FieldOffset(0)> Public ki As KEYBDINPUT
            <FieldOffset(0)> Public hi As HARDWAREINPUT
        End Structure
    
        Private Structure MOUSEINPUT
            Public dx As Integer
            Public dy As Integer
            Public mouseData As Integer
            Public dwFlags As Integer
            Public time As Integer
            Public dwExtraInfo As IntPtr
        End Structure
        Const INPUT_MOUSE As UInt32 = 0
        Const INPUT_KEYBOARD As Integer = 1
        Const INPUT_HARDWARE As Integer = 2
        Const KEYEVENTF_EXTENDEDKEY As UInt32 = &H1
        Const KEYEVENTF_KEYUP As UInt32 = &H2
        Const KEYEVENTF_UNICODE As UInt32 = &H4
        Const KEYEVENTF_SCANCODE As UInt32 = &H8
        Const XBUTTON1 As UInt32 = &H1
        Const XBUTTON2 As UInt32 = &H2
        Const MOUSEEVENTF_MOVE As UInt32 = &H1
        Const MOUSEEVENTF_LEFTDOWN As UInt32 = &H2
        Const MOUSEEVENTF_LEFTUP As UInt32 = &H4
        Const MOUSEEVENTF_RIGHTDOWN As UInt32 = &H8
        Const MOUSEEVENTF_RIGHTUP As UInt32 = &H10
        Const MOUSEEVENTF_MIDDLEDOWN As UInt32 = &H20
        Const MOUSEEVENTF_MIDDLEUP As UInt32 = &H40
        Const MOUSEEVENTF_XDOWN As UInt32 = &H80
        Const MOUSEEVENTF_XUP As UInt32 = &H100
        Const MOUSEEVENTF_WHEEL As UInt32 = &H800
        Const MOUSEEVENTF_VIRTUALDESK As UInt32 = &H4000
        Const MOUSEEVENTF_ABSOLUTE As UInt32 = &H8000
    
    
        Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
    
        End Sub
    End Class
    But it doesn’t work for me I’m getting those errors:

    Error 1 Identifier expected. C:\Documents and 2 91 WindowsApplication1
    Error 2 Type 'StructLayout' is not defined. C:\Documents and 26 6 WindowsApplication1
    Error 3 Type 'FieldOffset' is not defined. C:\Documents and 28 10 WindowsApplication1
    Error 4 Type 'FieldOffset' is not defined. C:\Documents and 29 10 WindowsApplication1
    Error 5 Type 'FieldOffset' is not defined. C:\Documents and 30 10 WindowsApplication1

    Please help!
    VB n00b with stupid questions
    Home site keywen.com

  2. #2
    Addicted Member ZenDisaster's Avatar
    Join Date
    Dec 2006
    Location
    Bay Area, CA
    Posts
    140

    Re: Need help with SendInput

    I dunno man, that's kind of a big nasty mess to do what SetCursorPos already does in like 2 lines.

    Code:
    Private Declare Function SetCursorPos Lib "user32.dll" ( _
        ByVal x As Int32, _
        ByVal y As Int32) As Int32
    Code:
    Call SetCursorPos(X, Y)

  3. #3

    Thread Starter
    Lively Member
    Join Date
    Jul 2009
    Posts
    127

    Re: Need help with SendInput

    Thanks bro, but I already knew that also you can use

    Code:
    Windows.Forms.Cursor.Position = New System.Drawing.Point(x, y)
    But I don’t want my cursor to jump araound I want it to move from one point to another, like human would. Can you help me with this?
    VB n00b with stupid questions
    Home site keywen.com

  4. #4
    Addicted Member ZenDisaster's Avatar
    Join Date
    Dec 2006
    Location
    Bay Area, CA
    Posts
    140

    Smile Re: Need help with SendInput

    Alright, I just did this a day or so ago.

    Check out this this post.

    You'll have to convert it to .NET but that won't be a big deal compared to the nightmare that is SendInput. On the plus side, this example is Unmanaged so it wont be blocked by Vista/7 security garbage trash like the managed SendInput would in cases.

    I'm still working on the SendInput just because I refuse to walk away whipped. Apparently nobody on the internet can get it right and those that can are guarding it like it were money.

    When I get it squared away I'll post back with a very clear and detailed explanation.

    Umm, if you manage to figure it out before I do, please post back here and give us all a break.

  5. #5
    Addicted Member ZenDisaster's Avatar
    Join Date
    Dec 2006
    Location
    Bay Area, CA
    Posts
    140

    Re: Need help with SendInput

    Ok 1 thing for sure.

    If you add Imports System.Runtime.InteropServices to the first line of your class, it should clear up your warnings.

Posting Permissions

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



Click Here to Expand Forum to Full Width