C# GeckoFX - 如何将 SendKeyEvent 与越南字符串一起使用

C# GeckoFX - How to use SendKeyEvent with Vietnamese string

我使用 GeckoFX 而不是 .NET webControl 组件来制作自动化工具,在 GeckoFX 中支持的方法被称为:SendKeyEvent()。 我想通过这种方法将带有越南语消息的字符串发送到浏览器,但输出是加密字符串:

示例字符串:

đây là tiếng việt

这是我的代码

byte[] tmp_cmt = Encoding.UTF8.GetBytes(comment);
char[] tmp_rsl = comment.ToCharArray();
txtLog.AppendText("Starting COMMENT....\n");
webBrowser1.Window.DomWindow.Focus();
int a = 0;
while (a < comment.Length)
{
    Thread.Sleep(100);
    bool sd = webBrowser1.Window.WindowUtils.SendKeyEvent("keypress", 0, tmp_cmt[a], 0, true);
    if (!sd) { Utilityx.Log(tmp_cmt[a].ToString() + " - "); a++; }
    Application.DoEvents();
}
txtLog.AppendText("Pressing `Enter` key to submit comment...\n");
webBrowser1.Window.WindowUtils.SendKeyEvent("keydown", 13, 0, 0, true);
webBrowser1.Window.WindowUtils.SendKeyEvent("keyup", 13, 0, 0, true);

结果如下:

?ay l? ti?ng vi?t

如何让它发挥作用? 提前致谢!

方法的签名是

SendKeyEvent(string aType, int aKeyCode, int aCharCode, int aModifiers, bool aPreventDefault)

我不知道 keyCode,你发送 0 是否重要,但肯定 charCode 不是 byte在字符串的 UTF8 编码中。相反,您应该尝试使用 (int)comment[a]

我在这里看到的问题是,对于越南字符,可能需要按下多个键。如果 SendKeyEvent 自己不知道如何翻译,那么您可能需要进行一些复杂的按键模拟。