【问题标题】:Visual Studio Extension KeyProcessor Alt KeyVisual Studio 扩展 KeyProcessor Alt 键
【发布时间】:2013-08-16 08:06:22
【问题描述】:

无法在 Alt+Key 上获取事件。示例 Alt+EEAlt 的事件触发,但没有 Alt+E IKeyProcessorProvider 中的 Mb 问题?我有用户控件,想要使用内部控件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); }
    }

【问题讨论】:

标签: c# visual-studio visual-studio-extensions


【解决方案1】:

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

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

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-11-22
    • 2019-02-09
    • 2012-04-11
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多