Using WPF InputBindings
and KeyBinding
, I am looking to find if there is a way to get when a keyboard input is being held down, and next when its being released (like the standard Preview
/KeyUp
hooks).
For example, if user was Holding CTRL+Right, I don't want a flood of messages into my ICommand
, but instead a single execution is wanted. When the CTRL+Right
is released (KeyUp), it would be nice to handle that with another KeyBinding.
I had considered inheriting from KeyBinding
or InputBinding
, but there are no events I can find to hook into so I can ignore the IsRepeat
of a a possible keyboard event.
I am not looking to do this is code-behind, this is entirely MVVM; Goal is to do this strictly with InputBindings
. This will be part of multiple controls, so preventing code-behind keeps the code clean without copy/paste.
<UserControl.InputBindings>
<KeyBinding Gesture="CTRL+Right"
Command="{Binding CommandHotKeyExecuted}"
CommandParameter="{x:Static SomeConstantValue}" />
</UserControl.InputBindings>
Would be sweet if this was available via the Gesture, but can't find anything other than simple statements like CTRL+Right
;
Reference:
Source for InputBinding
Source for KeyBinding
Alternate ideas that are not ideal -
Doesn't handle the KeyUp; Has CodeBehind requirements: SO: Ignore repetition in KeyBinding (holding the key - execute command just once)
Not talking about holding keys down: SO: Keybinding in WPF