728x90
728x170

KeyGesture 를 이용해서 특정 키입력 시 이벤트 처리를 할수 있습니다.

아래는 Ctrl과 X를 동시에 눌렀을 경우 팝업을 띄우는 예제입니다.

 

using System.Windows;

using System.Windows.Input;

 

namespace WpfApp

{

    /// <summary>

    /// MainWindow.xaml에 대한 상호 작용 논리

    /// </summary>

    public partial class MainWindow : Window

    {

        KeyGesture gestCut = new KeyGesture(Key.X, ModifierKeys.Control);

 

        public MainWindow()

        {

            InitializeComponent();

 

            Title = "KeyGesture";

        }

 

        protected override void OnPreviewKeyDown(KeyEventArgs args)

        {

            if (gestCut.Matches(null, args))

            {

                CtrlXMethod();

                args.Handled = true;

            }

        }

 

 

        private void CtrlXMethod()

        {

            MessageBox.Show("Ctrl+X");

        }

    }

}

 

 

 

728x90
그리드형
Posted by kjun
,