Reputation: 91
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); }
}
Upvotes: 0
Views: 867
Reputation: 91
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)
{
}
}
Upvotes: 2