扳机触发ALT

发布于 2025-01-27 16:04:09 字数 473 浏览 4 评论 0原文

我想从form1_keypress中检测Alt或Alt +一些键。这是我的代码:

    private void Form1_KeyPress(object sender, KeyPressEventArgs e)
    {

        if (Control.ModifierKeys == Keys.Alt)
        {
            MessageBox.Show("Alt");
        }
        if (Control.ModifierKeys == Keys.Control)
        {
            MessageBox.Show("Control");
        }
    }

当我击中ctrl + a时,第二个如果触发。但是,当我击中Alt + A时,什么也不会发生。这是为什么?是否还有其他方法可以从form1_keypress触发alt?在这种情况下,我不想从键盘触发它。

I want to detect Alt, or Alt + some key, from within Form1_KeyPress. This is my code:

    private void Form1_KeyPress(object sender, KeyPressEventArgs e)
    {

        if (Control.ModifierKeys == Keys.Alt)
        {
            MessageBox.Show("Alt");
        }
        if (Control.ModifierKeys == Keys.Control)
        {
            MessageBox.Show("Control");
        }
    }

When I hit Ctrl + A for example, the second if triggers. However when I hit Alt + A for example, nothing happens. Why is that? is there some other way to trigger Alt from Form1_KeyPress? I don't want to trigger it from KeyDown in this instance.

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

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

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文