private void Window_PreviewKeyDown(object sender, KeyEventArgs e) { //單個按鍵e.Key方式判斷 if (e.Key == Key.Enter) { MessageBox.Show("Key.Ent... ...
private void Window_PreviewKeyDown(object sender, KeyEventArgs e) { //單個按鍵e.Key方式判斷 if (e.Key == Key.Enter) { MessageBox.Show("Key.Enter"); //TODO } //Ctrl+C 複製 組合按鍵使用Modifiers 與 e.Key方式判斷 if (e.KeyboardDevice.Modifiers == ModifierKeys.Control && e.Key == Key.C) { MessageBox.Show("Ctrl+C"); //TODO } //Ctrl+X 剪切 組合鍵使用IsKeyDown方式判斷 if ((e.KeyboardDevice.IsKeyDown(Key.LeftCtrl) || e.KeyboardDevice.IsKeyDown(Key.RightCtrl)) && e.KeyboardDevice.IsKeyDown(Key.X)) { MessageBox.Show("Ctrl+X"); //TODO } //Shift+D 刪除 組合鍵使用Modifiers 與 IsKeyDown方式判斷 if (e.KeyboardDevice.Modifiers == ModifierKeys.Shift && e.KeyboardDevice.IsKeyDown(Key.Delete)) { MessageBox.Show("Ctrl+D"); //TODO } }