SendInput() inconsistency between 32/64 bit function equivalents

Discussion in 'Windows 64bit' started by =?Utf-8?B?TWFrc2lt?=, Aug 3, 2006.

  1. In C#, I made a program which sends Alt+Print key conbination using
    SendInput() function. The function works on 32 bit WinXP. My executable
    compiled for x86 also works on WinXP 64 bit. But when I use "AnyCPU" platform
    target, SendInput() still sends the keys, but they are not processed. After
    that, my left mouse button simulates my right one, until I press the right
    button. I also tested Shift+Print and it works the same. Could it be a bug in
    WinXP 64? I believe 32 and 64 bit dll versions should be identical. Anybody
    knows how to fix this?
    =?Utf-8?B?TWFrc2lt?=, Aug 3, 2006
    #1
    1. Advertising

  2. =?Utf-8?B?TWFrc2lt?=

    mabra Guest

    Hi !

    I am not a specialist on this, but made some similar things. Do do what
    you described, so far I remember correctly - you have to use PInvoke and
    the WIN32 API. Can you show your declarations please?

    The problem could stem from declaring pointer as integer instead of IntPtr.

    Just a thought,
    Manfred

    Maksim wrote:
    > In C#, I made a program which sends Alt+Print key conbination using
    > SendInput() function. The function works on 32 bit WinXP. My executable
    > compiled for x86 also works on WinXP 64 bit. But when I use "AnyCPU" platform
    > target, SendInput() still sends the keys, but they are not processed. After
    > that, my left mouse button simulates my right one, until I press the right
    > button. I also tested Shift+Print and it works the same. Could it be a bug in
    > WinXP 64? I believe 32 and 64 bit dll versions should be identical. Anybody
    > knows how to fix this?
    mabra, Aug 4, 2006
    #2
    1. Advertising

  3. Re: SendInput() inconsistency between 32/64 bit function equivalen

    At first that's what I thought, some wrong data type, but no I checked and
    rewrote all PInvoke stuff to match Win32 declaration exactly, here it is:

    // --------------------------->

    internal enum DeviceMessageType : uint
    {
    Mouse = 0,
    Keyboard = 1,
    }

    [StructLayout(LayoutKind.Sequential, Pack = 4)]
    internal struct Point
    {
    public int X; // LONG
    public int Y; // LONG
    }

    [StructLayout(LayoutKind.Sequential)]
    internal struct MouseMessage // MOUSEINPUT
    {
    public Point Position; // LONG X, LONG Y
    public uint MouseData; // DWORD
    public uint Flags; // DWORD
    public uint TimeStamp; // DWORD
    public UIntPtr ExtraInfo; // ULONG_PTR
    }

    internal enum VirtualKey : int
    {
    PrintScreen = 0x2C,
    Shift = 0x10,
    Control = 0x11,
    Alt = 0x12
    }

    internal enum KeyEvent : uint // DWORD
    {
    KeyUp = 0x0002
    }

    [StructLayout(LayoutKind.Sequential)]
    internal struct KeyboardMessage // KEYBDINPUT
    {
    public ushort VirtualKey; // WORD
    public ushort ScanCode; // WORD
    public KeyEvent KeyEvent; // DWORD
    public uint TimeStamp; // DWORD
    public UIntPtr ExtraInfo; // ULONG_PTR
    }

    [StructLayout(LayoutKind.Explicit)]
    internal struct DeviceMessageInfo // INPUT
    {
    [FieldOffset(0)]
    public DeviceMessageType DeviceMessageType;

    [FieldOffset(4)]
    public MouseMessage MouseMessage;

    [FieldOffset(4)]
    public KeyboardMessage KeyboardMessage;

    public DeviceMessageInfo(DeviceMessageType DeviceMessageType)
    {
    this.DeviceMessageType = DeviceMessageType;
    this.MouseMessage = new MouseMessage();
    this.KeyboardMessage = new KeyboardMessage();
    }

    public static readonly int SizeOf =
    Marshal.SizeOf(typeof(DeviceMessageInfo));
    }

    [DllImport("User32.dll", EntryPoint = "SendInput", ExactSpelling = true)]
    public static extern uint Send(uint Count, [In] DeviceMessageInfo[]
    DeviceMessageInfo, int DeviceMessageInfoSize);

    // <---------------------------

    I really need to make it work on WinXP x64, so if you find anything wrong
    with it, let me know.

    "mabra" wrote:

    > Hi !
    >
    > I am not a specialist on this, but made some similar things. Do do what
    > you described, so far I remember correctly - you have to use PInvoke and
    > the WIN32 API. Can you show your declarations please?
    >
    > The problem could stem from declaring pointer as integer instead of IntPtr.
    >
    > Just a thought,
    > Manfred
    >
    > Maksim wrote:
    > > In C#, I made a program which sends Alt+Print key conbination using
    > > SendInput() function. The function works on 32 bit WinXP. My executable
    > > compiled for x86 also works on WinXP 64 bit. But when I use "AnyCPU" platform
    > > target, SendInput() still sends the keys, but they are not processed. After
    > > that, my left mouse button simulates my right one, until I press the right
    > > button. I also tested Shift+Print and it works the same. Could it be a bug in
    > > WinXP 64? I believe 32 and 64 bit dll versions should be identical. Anybody
    > > knows how to fix this?

    >
    =?Utf-8?B?TWFrc2lt?=, Aug 4, 2006
    #3
  4. =?Utf-8?B?TWFrc2lt?=

    mabra Guest

    Re: SendInput() inconsistency between 32/64 bit function equivalen

    Hi !

    I would just give the hint.

    Sorry, I have never dealed with this APIs, just made some "SendMessage"
    calls, which suceeds.

    Best regards,
    Manfred

    Maksim wrote:
    > At first that's what I thought, some wrong data type, but no I checked and
    > rewrote all PInvoke stuff to match Win32 declaration exactly, here it is:
    >
    > // --------------------------->
    >
    > internal enum DeviceMessageType : uint
    > {
    > Mouse = 0,
    > Keyboard = 1,
    > }
    >
    > [StructLayout(LayoutKind.Sequential, Pack = 4)]
    > internal struct Point
    > {
    > public int X; // LONG
    > public int Y; // LONG
    > }
    >
    > [StructLayout(LayoutKind.Sequential)]
    > internal struct MouseMessage // MOUSEINPUT
    > {
    > public Point Position; // LONG X, LONG Y
    > public uint MouseData; // DWORD
    > public uint Flags; // DWORD
    > public uint TimeStamp; // DWORD
    > public UIntPtr ExtraInfo; // ULONG_PTR
    > }
    >
    > internal enum VirtualKey : int
    > {
    > PrintScreen = 0x2C,
    > Shift = 0x10,
    > Control = 0x11,
    > Alt = 0x12
    > }
    >
    > internal enum KeyEvent : uint // DWORD
    > {
    > KeyUp = 0x0002
    > }
    >
    > [StructLayout(LayoutKind.Sequential)]
    > internal struct KeyboardMessage // KEYBDINPUT
    > {
    > public ushort VirtualKey; // WORD
    > public ushort ScanCode; // WORD
    > public KeyEvent KeyEvent; // DWORD
    > public uint TimeStamp; // DWORD
    > public UIntPtr ExtraInfo; // ULONG_PTR
    > }
    >
    > [StructLayout(LayoutKind.Explicit)]
    > internal struct DeviceMessageInfo // INPUT
    > {
    > [FieldOffset(0)]
    > public DeviceMessageType DeviceMessageType;
    >
    > [FieldOffset(4)]
    > public MouseMessage MouseMessage;
    >
    > [FieldOffset(4)]
    > public KeyboardMessage KeyboardMessage;
    >
    > public DeviceMessageInfo(DeviceMessageType DeviceMessageType)
    > {
    > this.DeviceMessageType = DeviceMessageType;
    > this.MouseMessage = new MouseMessage();
    > this.KeyboardMessage = new KeyboardMessage();
    > }
    >
    > public static readonly int SizeOf =
    > Marshal.SizeOf(typeof(DeviceMessageInfo));
    > }
    >
    > [DllImport("User32.dll", EntryPoint = "SendInput", ExactSpelling = true)]
    > public static extern uint Send(uint Count, [In] DeviceMessageInfo[]
    > DeviceMessageInfo, int DeviceMessageInfoSize);
    >
    > // <---------------------------
    >
    > I really need to make it work on WinXP x64, so if you find anything wrong
    > with it, let me know.
    >
    > "mabra" wrote:
    >
    >> Hi !
    >>
    >> I am not a specialist on this, but made some similar things. Do do what
    >> you described, so far I remember correctly - you have to use PInvoke and
    >> the WIN32 API. Can you show your declarations please?
    >>
    >> The problem could stem from declaring pointer as integer instead of IntPtr.
    >>
    >> Just a thought,
    >> Manfred
    >>
    >> Maksim wrote:
    >>> In C#, I made a program which sends Alt+Print key conbination using
    >>> SendInput() function. The function works on 32 bit WinXP. My executable
    >>> compiled for x86 also works on WinXP 64 bit. But when I use "AnyCPU" platform
    >>> target, SendInput() still sends the keys, but they are not processed. After
    >>> that, my left mouse button simulates my right one, until I press the right
    >>> button. I also tested Shift+Print and it works the same. Could it be a bug in
    >>> WinXP 64? I believe 32 and 64 bit dll versions should be identical. Anybody
    >>> knows how to fix this?
    mabra, Aug 4, 2006
    #4
  5. Re: SendInput() inconsistency between 32/64 bit function equivalen

    So anybody knows how to make SendInput() to work on WinXP x64?

    "mabra" wrote:

    > Hi !
    >
    > I would just give the hint.
    >
    > Sorry, I have never dealed with this APIs, just made some "SendMessage"
    > calls, which suceeds.
    >
    > Best regards,
    > Manfred
    >
    > Maksim wrote:
    > > At first that's what I thought, some wrong data type, but no I checked and
    > > rewrote all PInvoke stuff to match Win32 declaration exactly, here it is:
    > >
    > > // --------------------------->
    > >
    > > internal enum DeviceMessageType : uint
    > > {
    > > Mouse = 0,
    > > Keyboard = 1,
    > > }
    > >
    > > [StructLayout(LayoutKind.Sequential, Pack = 4)]
    > > internal struct Point
    > > {
    > > public int X; // LONG
    > > public int Y; // LONG
    > > }
    > >
    > > [StructLayout(LayoutKind.Sequential)]
    > > internal struct MouseMessage // MOUSEINPUT
    > > {
    > > public Point Position; // LONG X, LONG Y
    > > public uint MouseData; // DWORD
    > > public uint Flags; // DWORD
    > > public uint TimeStamp; // DWORD
    > > public UIntPtr ExtraInfo; // ULONG_PTR
    > > }
    > >
    > > internal enum VirtualKey : int
    > > {
    > > PrintScreen = 0x2C,
    > > Shift = 0x10,
    > > Control = 0x11,
    > > Alt = 0x12
    > > }
    > >
    > > internal enum KeyEvent : uint // DWORD
    > > {
    > > KeyUp = 0x0002
    > > }
    > >
    > > [StructLayout(LayoutKind.Sequential)]
    > > internal struct KeyboardMessage // KEYBDINPUT
    > > {
    > > public ushort VirtualKey; // WORD
    > > public ushort ScanCode; // WORD
    > > public KeyEvent KeyEvent; // DWORD
    > > public uint TimeStamp; // DWORD
    > > public UIntPtr ExtraInfo; // ULONG_PTR
    > > }
    > >
    > > [StructLayout(LayoutKind.Explicit)]
    > > internal struct DeviceMessageInfo // INPUT
    > > {
    > > [FieldOffset(0)]
    > > public DeviceMessageType DeviceMessageType;
    > >
    > > [FieldOffset(4)]
    > > public MouseMessage MouseMessage;
    > >
    > > [FieldOffset(4)]
    > > public KeyboardMessage KeyboardMessage;
    > >
    > > public DeviceMessageInfo(DeviceMessageType DeviceMessageType)
    > > {
    > > this.DeviceMessageType = DeviceMessageType;
    > > this.MouseMessage = new MouseMessage();
    > > this.KeyboardMessage = new KeyboardMessage();
    > > }
    > >
    > > public static readonly int SizeOf =
    > > Marshal.SizeOf(typeof(DeviceMessageInfo));
    > > }
    > >
    > > [DllImport("User32.dll", EntryPoint = "SendInput", ExactSpelling = true)]
    > > public static extern uint Send(uint Count, [In] DeviceMessageInfo[]
    > > DeviceMessageInfo, int DeviceMessageInfoSize);
    > >
    > > // <---------------------------
    > >
    > > I really need to make it work on WinXP x64, so if you find anything wrong
    > > with it, let me know.
    > >
    > > "mabra" wrote:
    > >
    > >> Hi !
    > >>
    > >> I am not a specialist on this, but made some similar things. Do do what
    > >> you described, so far I remember correctly - you have to use PInvoke and
    > >> the WIN32 API. Can you show your declarations please?
    > >>
    > >> The problem could stem from declaring pointer as integer instead of IntPtr.
    > >>
    > >> Just a thought,
    > >> Manfred
    > >>
    > >> Maksim wrote:
    > >>> In C#, I made a program which sends Alt+Print key conbination using
    > >>> SendInput() function. The function works on 32 bit WinXP. My executable
    > >>> compiled for x86 also works on WinXP 64 bit. But when I use "AnyCPU" platform
    > >>> target, SendInput() still sends the keys, but they are not processed. After
    > >>> that, my left mouse button simulates my right one, until I press the right
    > >>> button. I also tested Shift+Print and it works the same. Could it be a bug in
    > >>> WinXP 64? I believe 32 and 64 bit dll versions should be identical. Anybody
    > >>> knows how to fix this?

    >
    =?Utf-8?B?TWFrc2lt?=, Aug 6, 2006
    #5
  6. =?Utf-8?B?TWFrc2lt?=

    WhatIThink

    Joined:
    Dec 2, 2008
    Messages:
    5
    Try this

    Try to muliplicate the values you send to sendinput by two if its on 64 bit.
    WhatIThink, Feb 12, 2010
    #6
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Alan D.

    Any digital equivalents of Olympus Stylus Epic?

    Alan D., Jan 3, 2004, in forum: Digital Photography
    Replies:
    5
    Views:
    860
    Dave Martindale
    Jan 3, 2004
  2. Cynicor

    Telescope-to-lens equivalents?

    Cynicor, Nov 30, 2004, in forum: Digital Photography
    Replies:
    8
    Views:
    512
    Greg Campbell
    Dec 1, 2004
  3. Jamie Turner

    SendInput Problems

    Jamie Turner, Feb 12, 2007, in forum: Windows 64bit
    Replies:
    5
    Views:
    615
    Tony Sperling
    Feb 13, 2007
  4. Radium
    Replies:
    476
    Views:
    5,581
    David J Taylor
    Aug 29, 2007
  5. IRO

    Win equivalents of Mac SW?

    IRO, Jan 15, 2004, in forum: NZ Computing
    Replies:
    12
    Views:
    585
    T.N.O. - Dave.net.nz
    Jan 16, 2004
Loading...

Share This Page