0

DotNetBrowser support input simulation but I can' t find a way to do it for foreign languages. The following code works for English. Any idea how to use VirtualKeyCode with non-English characters ?

// Press TAB key to set focus to text field.
KeyParams paramers = new KeyParams(VirtualKeyCode.TAB, ' ');
browser.KeyDown(paramers);
browser.KeyUp(paramers);

// Type 'Hello' text in the focused text field.
paramers = new KeyParams(VirtualKeyCode.VK_H, 'H');
browser.KeyDown(paramers);
browser.KeyUp(paramers);

paramers = new KeyParams(VirtualKeyCode.VK_E, 'e');
browser.KeyDown(paramers);
browser.KeyUp(paramers);

paramers = new KeyParams(VirtualKeyCode.VK_L, 'l');
browser.KeyDown(paramers);
browser.KeyUp(paramers);

paramers = new KeyParams(VirtualKeyCode.VK_L, 'l');
browser.KeyDown(paramers);
browser.KeyUp(paramers);

paramers = new KeyParams(VirtualKeyCode.VK_O, 'o');
browser.KeyDown(paramers);
browser.KeyUp(paramers);
theduck
  • 2,589
  • 13
  • 17
  • 23
Heopas
  • 69
  • 1
  • 10
  • In general you can't. The mapping of virtual keys (the same anywhere in the world) to specific letters that are relevant to the user's language and preferences depends on the keyboard layout that the user has selected. As well as the keyboard state. [Look here](https://stackoverflow.com/a/2899364/17034) for mapping code, but with the expectation that you'll find out this is a feature that should have been left out of this library. – Hans Passant Oct 05 '19 at 22:00

1 Answers1

0

I have found a solution. text is a string.

var stringSplit = text.Split(' ');
            for (int i = 0; i < stringSplit.Length; i++)
            {
                var characters = stringSplit[i].ToCharArray();
                foreach (var character in characters)
                {
                    var keyParams = new KeyParams(VirtualKeyCode.NONAME, character);
                    browser.KeyDown(keyParams);
                    browser.KeyUp(keyParams);
                }
                if (i < stringSplit.Length-1)
                {
                    var spaceKey = new KeyParams(VirtualKeyCode.SPACE, ' ');
                    browser.KeyDown(spaceKey);
                    browser.KeyUp(spaceKey);
                }
            }
Heopas
  • 69
  • 1
  • 10