Ключ Alt для процессора Visual Studio Extension

Не удается получить событие по Alt+Key. Пример Alt+E. Событие активируется для E и Alt, но нет проблем с Alt+E Mb в IKeyProcessorProvider? У меня есть пользовательский контроль, и я хочу использовать внутренний контроль 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); }
    }

person Sequd    schedule 16.08.2013    source источник
comment
Почему бы не проверить args.Alt?   -  person Matthew Watson    schedule 16.08.2013


Ответы (1)


Правильный код. Нужны используемые args.SystemKey и Keyboard.Modifiers.

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