wpf中界面获取鼠标或键盘操作

2017-06-06 19:09:47来源:CSDN作者:qq_31971935人点击

前台:加上:KeyDown=”Window_KeyDown”

<Window x:Class="BIMClient.Views.BIMWindow"        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"        xmlns:Controls="clr-namespace:Autodesk.Navisworks.Api.Controls;assembly=Autodesk.Navisworks.Controls"        xmlns:form="clr-namespace:System.Windows.Forms;assembly=System.Windows.Forms"        Title="BIMWindow"   KeyDown="Window_KeyDown" WindowState="Maximized"> </window> 

后台:

    #region 快捷键        private void Window_KeyDown(object sender, KeyEventArgs e)        {            if ((e.KeyboardDevice.Modifiers & ModifierKeys.Control) == ModifierKeys.Control)            {                switch (e.Key)                {                    case Key.D1:                        //将要执行代码                        break;                    case Key.D2:                        break;                    case Key.D3:                        break;                    case Key.D4:                        break;                    case Key.D5:                        break;                    case Key.D6:                        break;                    case Key.D7:                        break;                    case Key.D8:                        break;                    case Key.D9:                        break;                    case Key.Q:                        break;                    case Key.W:                        break;                    case Key.E:                        break;                    case Key.R:                        break;                    case Key.T:                        break;                    case Key.Y:                        break;                    case Key.U:                        break;                    case Key.I:                        break;                    case Key.O:                        break;                    case Key.P:                        break;                    case Key.A:                        break;                    case Key.S:                        break;                    case Key.D:                        break;                    case Key.F:                        break;                    case Key.G:                        break;                    case Key.Space:                        break;                    case Key.Z:                        break;                    case Key.X:                        break;                }            }        }        #endregion

最新文章

123

最新摄影

闪念基因

微信扫一扫

第七城市微信公众平台