locked
SendInput vs Windows 7 x64 RC Build 7000 not working

    Question

  • Hello, i use following

        Private Declare Function SendInput Lib "user32" (ByVal nInputs As Integer, ByVal pInputs() As INPUT, ByVal cbSize As Integer) As Integer
    
        Private Const KEYEVENTF_KEYUP As Integer = &H2
        Private Const INPUT_MOUSE As Integer = 0
        Private Const INPUT_KEYBOARD As Integer = 1
        Private Const INPUT_HARDWARE As Integer = 2
    
        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
    
        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
    
        Private Structure INPUT
            <FieldOffset(0)> Public type As Integer
            <FieldOffset(4)> Public mi As MOUSEINPUT
            <FieldOffset(4)> Public ki As KEYBDINPUT
            <FieldOffset(4)> Public hi As HARDWAREINPUT
        End Structure
    
        Private Sub SendKey(ByVal bKey As Short, ByVal KeyDown As Boolean)
            Dim GInput(1) As INPUT
            If KeyDown = True Then
                GInput(0).type = INPUT_KEYBOARD
                GInput(0).ki.wVk = bKey
                GInput(0).ki.dwFlags = 0
            ElseIf KeyDown = False Then
                GInput(1).type = INPUT_KEYBOARD
                GInput(1).ki.wVk = bKey
                GInput(1).ki.dwFlags = KEYEVENTF_KEYUP
            End If
            SendInput(2, GInput, Marshal.SizeOf(GetType(INPUT)))
        End Sub
    
    

    Wich works on Windows Vista Business x86 Sp1, but not on Windows 7 x64 RC Build 7000. I read somewhere that it has to do with the 32/64 bit editions. What do i need to do to get it working on Windows 7.

    • Edited by ddaemen Wednesday, July 29, 2009 9:13 AM
    Wednesday, July 29, 2009 9:03 AM

Answers

  •  Private Structure INPUT
            <FieldOffset(0)> Public type As Integer
            <FieldOffset(4)> Public mi As MOUSEINPUT
            <FieldOffset(4)> Public ki As KEYBDINPUT
            <FieldOffset(4)> Public hi As HARDWAREINPUT
        End Structure

    should be switched to:

     Private Structure INPUT
            <FieldOffset(0)> Public type As Integer
            <FieldOffset(8)> Public mi As MOUSEINPUT
            <FieldOffset(8)> Public ki As KEYBDINPUT
            <FieldOffset(8)> Public hi As HARDWAREINPUT
        End Structure

    On a 64 bits OS (64 bits tends to double everything), though, i am also still having some problems making it work for some type of inputs.

    Hope it helps,
    Regards
    • Marked as answer by ddaemen Monday, November 30, 2009 9:16 AM
    Thursday, October 01, 2009 7:57 PM

All replies

  • Is this fixed?
    Any workaround to fix the problem?
    Monday, September 07, 2009 1:02 PM
  •  Private Structure INPUT
            <FieldOffset(0)> Public type As Integer
            <FieldOffset(4)> Public mi As MOUSEINPUT
            <FieldOffset(4)> Public ki As KEYBDINPUT
            <FieldOffset(4)> Public hi As HARDWAREINPUT
        End Structure

    should be switched to:

     Private Structure INPUT
            <FieldOffset(0)> Public type As Integer
            <FieldOffset(8)> Public mi As MOUSEINPUT
            <FieldOffset(8)> Public ki As KEYBDINPUT
            <FieldOffset(8)> Public hi As HARDWAREINPUT
        End Structure

    On a 64 bits OS (64 bits tends to double everything), though, i am also still having some problems making it work for some type of inputs.

    Hope it helps,
    Regards
    • Marked as answer by ddaemen Monday, November 30, 2009 9:16 AM
    Thursday, October 01, 2009 7:57 PM
  • I bet keybd_event and mouse_event still work, despite all the warnings to use SendInput.  They have performed admirably from Win95 throught Vista in all bits and platforms.
    Thursday, October 01, 2009 9:56 PM
  • If you can get away with it.. if you compile with x86 settings your original code should work.

    I've had major problems with SendInput and also with LVM_GETITEMTEXT since I moved to windows 7.

    Compiling the code in x64 or AnyCpu does not seem to work.

    Compiling in x86 seems to have solved my problems.
    Saturday, November 07, 2009 4:19 PM
  • workaround - compile in x86 instead of x64 or AnyCpu

    Saturday, November 07, 2009 4:21 PM
  • sorry for late response but thanks Chryzo, that solved my problems, the older ways like keyb_event do not work in windows 7 anymore
    Monday, November 30, 2009 9:17 AM