Disable normal behavior of Alt key

风流意气都作罢 提交于 2019-12-02 01:50:14
Chris Haas

My first answer is to NOT use the Alt key for your program and use Ctrl instead. Blocking "normal" things from happening usually leads to pain in the future.

But if you must use the Alt key I would check out this article which uses message filters to try and intercept it at the application level.

If that doesn't do what you're looking for, you might need to look into Global hooks, this link will get you started down the path. Global hooks are generally considered evil so you should only use this if the above two suggestions don't work. You must make sure that you uninstall your hooks otherwise you might find that you need to reboot your computer often to fix weird keyboard problems.

This works for me:

    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());
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!