Beispiel #1
0
        /// <summary>
        /// 接收消息,响应快捷键
        /// </summary>
        /// <param name="m"></param>
        protected override void WndProc(ref Message m)
        {
            // 收到的不是快捷键消息,不作任何处理
            if (m.Msg != 0x312)
            {
                base.WndProc(ref m);
                return;
            }

            // 收到的快捷键的值
            var keyValue = m.WParam.ToInt32();

            var key = (HotKeyType)keyValue;

            var lasttime = lastPressTime[key];
            var now      = DateTime.Now;

            var doubleClick = (now - lasttime).TotalSeconds <= 1;

            switch (key)
            {
            // 切换显示模式
            case HotKeyType.SwitchMode:
                SwitchDisplayMode();
                break;

            // 显示/隐藏更多的颜色格式
            case HotKeyType.SwitchDisplayMode:
                SwitchFormatMode();
                break;

            // 复制颜色值
            case HotKeyType.CopyColor:
                CopyColor(doubleClick);
                break;

            // 切换复制策略
            case HotKeyType.CopyPolicy:
                ToggleCopyPolicy();
                break;

            // 打开预览窗口
            case HotKeyType.ShowPreview:
                TogglePreview();
                break;

            // 显示/隐藏调色板
            case HotKeyType.ShowColorPicker:
                ShowColorPicker();
                break;

            // 绘制预览窗口
            case HotKeyType.ControlDraw:
                DrawControl(doubleClick);
                break;

            // 设置窗口在最前显示
            case HotKeyType.BringToTop:
                if (Visible)
                {
                    BringToFront();
                }
                if (previewForm != null && previewForm.Visible)
                {
                    previewForm.BringToFront();
                }
                break;

            // 使用像素放大算法
            case HotKeyType.PixelScale:
                Settings.Preview.PixelScale = !Settings.Preview.PixelScale;
                break;

            // 截图
            case HotKeyType.ScreenShot:
                if (ScreenShot.Busy)
                {
                    ScreenShot.CancelCapture();
                }
                else
                {
                    ScreenShot.Capture();
                }
                break;

            // 录屏
            case HotKeyType.ScreenRecord:
                ScreenShot.Record();
                break;

            default:
                throw new ArgumentOutOfRangeException();
            }

            lastPressTime[key] = now;

            base.WndProc(ref m);
        }