禁用Alt键的正常行为 [英] Disable normal behavior of Alt key

查看:140
本文介绍了禁用Alt键的正常行为的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

Alt 键时,通常焦点将移至窗口菜单.我需要全局禁用它.因为我的应用程序可以使用 Alt 键.当用户按下某个键并结合 Alt 键时,我的应用程序将另一个键发送到活动应用程序.因此,在打开菜单时,我只需要忽略 Alt .

When pressing the Alt key, normally the focus goes to the window's menu. I need to disable it globally. Because my application works with Alt key. When the user presses some key in combination with the Alt key, my application sends another key to active application. So I just need to ignore Alt when it opens the menu.

我是编程新手,正在寻找VB.Net或C#代码.

I'm new to programming and I'm looking for VB.Net or C# code.

推荐答案

这对我有用:

    private class AltKeyFilter : IMessageFilter
    {
        public bool PreFilterMessage(ref Message m)
        {
            return m.Msg == 0x0104 && ((int)m.LParam & 0x20000000) != 0;
        }
    }

然后添加消息过滤器,如下所示:

And then you add the message filter like so:

Application.AddMessageFilter(new AltKeyFilter());

这篇关于禁用Alt键的正常行为的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆