Unable to simulate accented characters using extended keyboard (dead keys)

Jun 26, 2012 at 5:07 AM

Hi, 

I need to make a multilingual virtual keyboard. It should have support for accented characters like â, ƒ etc.

Normally we make such characters by pressing alt key, typing a sequence on numpad (e.g. 131) and releasing alt key. It works with manual input, but i am not able to simulate such action from input simulator.

I have tried SimulateModifiedKeystoke, extended key board patch given by you, tried adding some delay, tried code in http://inputsimulator.codeplex.com/discussions/235928 . But nothing seems to be fixing this.

Any help would be sincerely appreciated as I am in a big fix. 

Modifed Code :

List<VirtualKeyCode> myList = new List<VirtualKeyCode>();
            myList.Add(VirtualKeyCode.NUMPAD1);
            myList.Add(VirtualKeyCode.NUMPAD3);
            myList.Add(VirtualKeyCode.NUMPAD1);
            InputSimulator.SimulateModifiedKeyStroke(VirtualKeyCode.MENU, myList);

 

public static void SimulateKeyPress(VirtualKeyCode keyCode)
        {
            bool isExtendedKey = InputSimulator.IsExtendedKey(keyCode);
 
            uint KEYEVENTF_EXTENDEDKEY = 0x0001;
            uint KEYEVENTF_KEYUP = 0x0002;
 
            var down = new INPUT();
            down.Type = (UInt32)InputType.KEYBOARD;
            down.Data.Keyboard = new KEYBDINPUT();
            down.Data.Keyboard.Vk = (UInt16)keyCode;
            down.Data.Keyboard.Scan = 0;
            down.Data.Keyboard.Flags = 0;
            down.Data.Keyboard.Time = 0;
            down.Data.Keyboard.dwFlags = KEYEVENTF_EXTENDEDKEY;
            down.Data.Keyboard.ExtraInfo = IntPtr.Zero;
            
            // If this is an extended key, send the correct flag.
            if (isExtendedKey)
            {
                down.Data.Keyboard.Flags = (UInt32)KeyboardFlag.EXTENDEDKEY;
            }
 
            var up = new INPUT();
            up.Type = (UInt32)InputType.KEYBOARD;
            up.Data.Keyboard = new KEYBDINPUT();
            up.Data.Keyboard.Vk = (UInt16)keyCode;
            up.Data.Keyboard.Scan = 0;
            up.Data.Keyboard.Flags = (UInt32)KeyboardFlag.KEYUP;
            up.Data.Keyboard.Time = 0;
            up.Data.Keyboard.dwFlags = KEYEVENTF_EXTENDEDKEY | KEYEVENTF_KEYUP; 
            up.Data.Keyboard.ExtraInfo = IntPtr.Zero;
 
            
            // If this is an extended key, send the correct flag.
            if (isExtendedKey)
            {
                up.Data.Keyboard.Flags = up.Data.Keyboard.Flags | (UInt32)KeyboardFlag.EXTENDEDKEY;
            }
 
            INPUT[] inputList = new INPUT[2];
            inputList[0] = down;
            inputList[1] = up;
 
            var numberOfSuccessfulSimulatedInputs = SendInput(2, inputList, Marshal.SizeOf(typeof(INPUT)));
            if (numberOfSuccessfulSimulatedInputs == 0) throw new Exception(string.Format("The key press simulation for {0} was not successful.", keyCode));
        }

 

Coordinator
Jun 26, 2012 at 10:05 PM
Hi There,

Take a look at this discussion where somebody was trying to do the same thing. Hopefully that helps.


Mike

On Tue, Jun 26, 2012 at 3:07 PM, amitkumarbhati <notifications@codeplex.com> wrote:

From: amitkumarbhati

Hi,

I need to make a multilingual virtual keyboard. It should have support for accented characters like â, ƒ etc.

Normally we make such characters by pressing alt key, typing a sequence on numpad (e.g. 131) and releasing alt key. It works with manual input, but i am not able to simulate such action from input simulator.

I have tried SimulateModifiedKeystoke, extended key board patch given by you, tried adding some delay, tried code in http://inputsimulator.codeplex.com/discussions/235928 . But nothing seems to be fixing this.

Any help would be sincerely appreciated as I am in a big fix.

Modifed Code :

List<VirtualKeyCode> myList = new List<VirtualKeyCode>();
            myList.Add(VirtualKeyCode.NUMPAD1);
            myList.Add(VirtualKeyCode.NUMPAD3);
            myList.Add(VirtualKeyCode.NUMPAD1);
            InputSimulator.SimulateModifiedKeyStroke(VirtualKeyCode.MENU, myList);

public static void SimulateKeyPress(VirtualKeyCode keyCode)
        {
            bool isExtendedKey = InputSimulator.IsExtendedKey(keyCode);
 
            uint KEYEVENTF_EXTENDEDKEY = 0x0001;
            uint KEYEVENTF_KEYUP = 0x0002;
 
            var down = new INPUT();
            down.Type = (UInt32)InputType.KEYBOARD;
            down.Data.Keyboard = new KEYBDINPUT();
            down.Data.Keyboard.Vk = (UInt16)keyCode;
            down.Data.Keyboard.Scan = 0;
            down.Data.Keyboard.Flags = 0;
            down.Data.Keyboard.Time = 0;
            down.Data.Keyboard.dwFlags = KEYEVENTF_EXTENDEDKEY;
            down.Data.Keyboard.ExtraInfo = IntPtr.Zero;
            
            // If this is an extended key, send the correct flag.
            if (isExtendedKey)
            {
                down.Data.Keyboard.Flags = (UInt32)KeyboardFlag.EXTENDEDKEY;
            }
 
            var up = new INPUT();
            up.Type = (UInt32)InputType.KEYBOARD;
            up.Data.Keyboard = new KEYBDINPUT();
            up.Data.Keyboard.Vk = (UInt16)keyCode;
            up.Data.Keyboard.Scan = 0;
            up.Data.Keyboard.Flags = (UInt32)KeyboardFlag.KEYUP;
            up.Data.Keyboard.Time = 0;
            up.Data.Keyboard.dwFlags = KEYEVENTF_EXTENDEDKEY | KEYEVENTF_KEYUP; 
            up.Data.Keyboard.ExtraInfo = IntPtr.Zero;
 
            
            // If this is an extended key, send the correct flag.
            if (isExtendedKey)
            {
                up.Data.Keyboard.Flags = up.Data.Keyboard.Flags | (UInt32)KeyboardFlag.EXTENDEDKEY;
            }
 
            INPUT[] inputList = new INPUT[2];
            inputList[0] = down;
            inputList[1] = up;
 
            var numberOfSuccessfulSimulatedInputs = SendInput(2, inputList, Marshal.SizeOf(typeof(INPUT)));
            if (numberOfSuccessfulSimulatedInputs == 0) throw new Exception(string.Format("The key press simulation for {0} was not successful.", keyCode));
        }

Read the full discussion online.

To add a post to this discussion, reply to this email (inputsimulator@discussions.codeplex.com)

To start a new discussion for this project, email inputsimulator@discussions.codeplex.com

You are receiving this email because you subscribed to this discussion on CodePlex. You can unsubscribe or change your settings on codePlex.com.

Please note: Images and attachments will be removed from emails. Any posts to this discussion will also be available online at codeplex.com