我的目標是復制從Visual Studio編輯器鍵盤線組合Ctrl E V,可以完全實作一致。需要明確的是,這不是關于如何復制一行的問題,而是在 WPF 中處理鍵盤和弦場景的問題。
如何完成一個和弦
- 該CtrlV獨立將不會觸發自定義線復制命令,只是無法處理的時候E已經沒有它的陪伴。
- AKA 回退到系統做一個粘貼。
- 這不是交易破壞者,如果是這樣,我可以處理剪貼板。
我試過了
<KeyBinding Gesture="Ctrl E" Command="{Binding cmdSetChord_E}"/>
<KeyBinding Gesture="Ctrl V" Command="{Binding cmdDuplicateCurrent}"/>
和
bool ePressed;
private void tbPatternDesign_KeyDown(object sender, KeyEventArgs e)
{
if (Keyboard.Modifiers == ModifierKeys.Control && e.Key == Key.E)
ePressed = e.Handled = true;
if (ePressed && Keyboard.Modifiers == ModifierKeys.Control && e.Key == Key.V)
{
MessageBox.Show("Duplicate");
e.Handled = true;
ePressed = false;
}
}
無濟于事。
uj5u.com熱心網友回復:
您可以使用CommandBinding來覆寫控制元件的默認命令實作。這是一個帶有TextBox.
<TextBox>
<TextBox.CommandBindings>
<CommandBinding Command="ApplicationCommands.Paste" Executed="CommandBinding_Executed"/>
<CommandBinding Command="EditingCommands.AlignCenter" Executed="CommandBinding_Executed"/>
</TextBox.CommandBindings>
<TextBox.InputBindings>
<KeyBinding Command="EditingCommands.AlignCenter" Gesture="CTRL E"/>
</TextBox.InputBindings>
</TextBox>
bool ePressed;
private void CommandBinding_Executed(object sender, ExecutedRoutedEventArgs e)
{
switch (((RoutedUICommand)e.Command).Text)
{
case "Paste":
if (ePressed)
{
MessageBox.Show("Duplicate");
ePressed = false;
}
else
((TextBox)sender).Paste();
break;
case "AlignCenter":
ePressed = true;
break;
}
}
uj5u.com熱心網友回復:
怎么樣:
Keyboard.IsKeyDown(Key.E) && Keyboard.IsKeyDown(Key.V) && ...
uj5u.com熱心網友回復:
嘗試使用 Console.readkey。它可能不是最直觀的方法,但它是一個很好的現在的解決方案。
轉載請註明出處,本文鏈接:https://www.uj5u.com/qukuanlian/376377.html
