Visual Studio 扩展键处理器 Alt 键 [英] Visual Studio Extension KeyProcessor Alt Key

查看:22
本文介绍了Visual Studio 扩展键处理器 Alt 键的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

无法在 Alt+Key 上获取事件.示例 Alt+E.EAlt 的事件触发,但没有 Alt+EIKeyProcessorProvider 中的 Mb 问题?我有用户控件,想要使用内部控件 ButtonKeyProc.KeyDownEvent+=.

Cant get event on Alt+Key. Example Alt+E. Event firing for E and Alt, but no Alt+E Mb problem in IKeyProcessorProvider? I have usercontrol, and want used inner control ButtonKeyProc.KeyDownEvent+=.

[Export(typeof(IKeyProcessorProvider))]
[TextViewRole(PredefinedTextViewRoles.Document)]
[ContentType("any")]
[Name("ButtonProvider")]
[Order(Before = "default")]
internal class ButtonProvider : IKeyProcessorProvider
{
    [ImportingConstructor]
    public ButtonProvider()
    {
    }

    public KeyProcessor GetAssociatedProcessor(IWpfTextView wpfTextView)
    {
        return new ButtonKeyProc(wpfTextView);
    }
}


internal class ButtonKeyProc : KeyProcessor
{
    internal static event KeyEventHandler KeyDownEvent;

    public ButtonKeyProc(ITextView textView)
    {
    }

    public override void KeyDown(KeyEventArgs args)
    {
        if (args.Key == Key.E && IsAlt)
        {
            if (KeyDownEvent != null)
            {
                KeyDownEvent(this, args);
            }
        }           
    }

    public bool IsAlt
    {
        get { return Keyboard.IsKeyDown(Key.LeftAlt) || Keyboard.IsKeyDown(Key.RightAlt); }
    }

推荐答案

正确的代码.需要使用 args.SystemKey 和 Keyboard.Modifiers.

The correct code. Need used args.SystemKey and Keyboard.Modifiers.

public override void KeyDown(KeyEventArgs args)
{
    if (args.SystemKey == Key.E && (Keyboard.Modifiers & ModifierKeys.Alt) != 0)
    {            
    }           
}

这篇关于Visual Studio 扩展键处理器 Alt 键的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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