[main] enter key vs. [numpad] enterkey

Oct 26, 2011 at 11:28 PM

hi (again),

anyway to determine the numpad ENTER?

thankyou in advance,


Jun 20, 2012 at 4:42 PM

Sorry for the late reply, I have finally gotten back around to this project.

Unfortunately in this library there is no differentiation between the two, in our AutomationFramework we needed to tell the difference so we had to use straight Interop with SendInput (as opposed to using this library). If someone is feeling adventurous enough please feel free to integrate the changes into the main code line, I am not sure what the VirtualKey should be defined as (I'd vote for TEN_KEY_ENTER)

The "secret sauce" is that the Numeric Enter must have the KEYEVENTF_EXTENDEDKEY flag sent in its dwFlags. This is the root cause of another issue that I posted here http://inputsimulator.codeplex.com/discussions/235928. There is a list of keys that must have the KEYEVENTF_EXTENDEDKEY appended to them I am working on cleaning up/documenting our changes to submit them back to the project as we speak.

// -----------------------------------------------------------------------
// <copyright file="Program.cs">
//  This code is released into the public domain.
// </copyright>
// -----------------------------------------------------------------------

namespace InputSimulatorTest
    using System;
    using System.Runtime.InteropServices;

    class Program
        /// <summary>
        /// Simulate sending a 10-key 'Enter'
        /// </summary>
        static void Main(string[] args)
            //Make sure the Window is Focused Before this timeout is up

            // Hold the 10-key 'Enter'
            INPUT down = new INPUT();
            down.Type = INPUT_KEYBOARD;
            down.Data.Keyboard = new KEYBDINPUT();
            down.Data.Keyboard.wVk = VK_RETURN;
            down.Data.Keyboard.wScan = SC_RETURN;
            down.Data.Keyboard.dwFlags = KEYEVENTF_EXTENDEDKEY;
            down.Data.Keyboard.time = 0;
            down.Data.Keyboard.dwExtraInfo = IntPtr.Zero;

            // Release the 10-key 'Enter'
            INPUT up = new INPUT();
            up.Type = INPUT_KEYBOARD;
            up.Data.Keyboard = new KEYBDINPUT();
            up.Data.Keyboard.wVk = VK_RETURN;
            up.Data.Keyboard.wScan = SC_RETURN;
            up.Data.Keyboard.dwFlags = KEYEVENTF_EXTENDEDKEY | KEYEVENTF_KEYUP;
            up.Data.Keyboard.time = 0;
            up.Data.Keyboard.dwExtraInfo = IntPtr.Zero;

            // Declare the Input
            INPUT[] inputList = new INPUT[] { down, up };

            // Ensure that all inputs were entered
            uint sentkeys = SendInput(2, inputList, Marshal.SizeOf(typeof(INPUT)));
            if (sentkeys != 2)
                throw new ArgumentException("FAIL");

        #region Win32API

        const int INPUT_MOUSE = 0;
        const int INPUT_KEYBOARD = 1;
        const int INPUT_HARDWARE = 3;

        const byte VK_RETURN = 0x0D;
        const byte SC_RETURN = 0x1C;

        const uint KEYEVENTF_EXTENDEDKEY = 0x0001;
        const uint KEYEVENTF_KEYUP = 0x0002;

        [DllImport("user32.dll", SetLastError = true)]
        private static extern uint SendInput(uint numberOfInputs, INPUT[] inputs, int sizeOfInputStructure);

        internal struct INPUT
            public uint Type;
            public MOUSEKEYBDHARDWAREINPUT Data;

        internal struct MOUSEKEYBDHARDWAREINPUT
            // Fields
            public HARDWAREINPUT Hardware;
            public KEYBDINPUT Keyboard;
            public MOUSEINPUT Mouse;

        internal struct KEYBDINPUT
            public ushort wVk;
            public ushort wScan;
            public uint dwFlags;
            public uint time;
            public IntPtr dwExtraInfo;

        internal struct MOUSEINPUT
            public int X;
            public int Y;
            public uint MouseData;
            public uint Flags;
            public uint Time;
            public IntPtr ExtraInfo;

        internal struct HARDWAREINPUT
            public uint Msg;
            public ushort ParamL;
            public ushort ParamH;


Jul 11, 2012 at 11:44 AM


I found the same problem. Actually, not specifying extended resulted in extended being active (at least with keybd_event which does not have that parameter), so if you send input to an application that distinguishes NumPad keys, enter, +, -, ... will be treated as NumPad keys.

Mind you, so far I used SendMessage, now I will use SendInput (for SendMessage you need a destination Handle which is not always easy to determine). So I have high hopes of SendInput. And this project. :)