HtmlElementEventArgs KeyPressedCode 混乱

发布于 2024-07-28 23:27:18 字数 578 浏览 2 评论 0原文

我使用以下代码来确定是否为“.” (句号)已输入到网页浏览器控件中:

    private void body_KeyUp(object sender, HtmlElementEventArgs e)
    {
        if (e.KeyPressedCode == '.')
        {
            // Do something
        }
    }

根据msdn KeyPressedCode 返回一个ASCII 值。 如果我输入“.”,通过断点得到的结果是“190”。 然而。 这甚至没有在标准 ASCII 表中列出。 显然我可以简单地测试 190,但我担心 KeyPressedCode 可能会在具有不同代码页、语言等的不同系统上返回不同的值。

那么您能否解释一下为什么 KeyPressedCode 返回“190”而不是“46”以及如何“安全”地处理这个问题?

有趣的是,“ ”(空格)的返回值始终是正确的(“32”)。 使用 System.Text.Encoding.GetEncoding 和不同的代码页并没有解决问题,但是我对代码页没有太多经验。

I'm using the following code to decide if a '.' (full stop) has been entered into a webbrowser control:

    private void body_KeyUp(object sender, HtmlElementEventArgs e)
    {
        if (e.KeyPressedCode == '.')
        {
            // Do something
        }
    }

According to msdn KeyPressedCode returns an ASCII value. What I get by breakpointing is '190' if I enter a '.' however. This is not even listed in the standard ASCII table.
Obviously I could simply test for 190 but I fear that KeyPressedCode might return different values on different systems with different code pages, languages and so on.

So can you please explain me why KeyPressedCode returns '190' instead of '46' and how I can manage this problem 'safely'?

Interestingly enough the return value for ' ' (space) is always correct ('32').
Playing with System.Text.Encoding.GetEncoding and different code pages didn't solve the problem, I don't have much experience with code pages however.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

白馒头 2024-08-04 23:27:18

您可能使用的是有线键盘,因为键码 190 是 . 的 OEM 数字键码。 如果您使用的是笔记本电脑,它会按照您的预期运行。

You were likely using a wired keyboard, because keycode 190 is an OEM number keycode of .. If you were using a laptop it would behave as you expected.

无妨# 2024-08-04 23:27:18

只是一个疯狂的猜测,但是您检查过 e.AltKeyPressede.CtrlKeyPressede.ShiftKeyPressed 的值吗? 希望你能明白我的意思...

Just a wild guess, but have you checked the values of e.AltKeyPressed , e.CtrlKeyPressed and e.ShiftKeyPressed ? Hope you see what I'm getting at...

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文