private void HookKeyboard(ref KeyboardHook.StateKeyboard s) { // 就職キー処理 switch (s.Key) { case Keys.ShiftKey: modifiers = s.Stroke == KeyboardHook.Stroke.KEY_DOWN ? modifiers | Modifiers.Shift : modifiers & ~Modifiers.Shift; break; case Keys.LShiftKey: modifiers = s.Stroke == KeyboardHook.Stroke.KEY_DOWN ? modifiers | Modifiers.LShift : modifiers & ~Modifiers.LShift; break; case Keys.RShiftKey: modifiers = s.Stroke == KeyboardHook.Stroke.KEY_DOWN ? modifiers | Modifiers.RShift : modifiers & ~Modifiers.RShift; break; case Keys.ControlKey: modifiers = s.Stroke == KeyboardHook.Stroke.KEY_DOWN ? modifiers | Modifiers.Control : modifiers & ~Modifiers.Control; break; case Keys.LControlKey: modifiers = s.Stroke == KeyboardHook.Stroke.KEY_DOWN ? modifiers | Modifiers.LControl : modifiers & ~Modifiers.LControl; break; case Keys.RControlKey: modifiers = s.Stroke == KeyboardHook.Stroke.KEY_DOWN ? modifiers | Modifiers.RControl : modifiers & ~Modifiers.RControl; break; } // 押している時のみ移動 if (confHotKey != Keys.None && confHotKey == s.Key) { hotKey = s.Stroke == KeyboardHook.Stroke.KEY_DOWN; } if (s.Stroke == KeyboardHook.Stroke.KEY_DOWN) { // 中央に移動 if (confMoveToCenterKey != Keys.None && confMoveToCenterKey == s.Key && ((modifiers & confMoveToCenterKeyModifiers) != Modifiers.None)) { System.Diagnostics.Debug.WriteLine("Move To Center Key"); } // 選択して移動 // 場所を表示 // 終了 previousKey = s.Key; previousTime = s.Time; System.Diagnostics.Debug.WriteLine(string.Format("s.Stroke {0}, s.Key {1}, s.ScanCode {2}, s.Flags {3}, s.Time {4}, s.ExtraInfo {5}, modifiers{6}", s.Stroke, s.Key, s.ScanCode, s.Flags, s.Time, s.ExtraInfo, modifiers)); } }
/// <summary> /// キーフックのイベントメソッド /// </summary> /// <param name="state">キーボードの状態</param> void KeyboardHook_GetKeyState(ref KeyboardHook.StateKeyboard state) { if (this.isCapturing && state.Stroke == KeyboardHook.Stroke.KEY_UP) { this.isCapturing = false; } else if (this.isCapturing) { return; } else if (!this.isCapturing && state.Stroke == KeyboardHook.Stroke.KEY_DOWN) { this.isCapturing = true; } #if DEBUG Debug.WriteLine($"Ctrl:{state.WithControl.ToString()}, Shift:{state.WithShift.ToString()}, Alt:{state.WithAlt.ToString()}, F11:{(state.Key == Keys.F11).ToString()}"); #endif // Ctrlキー if (state.WithControl) { // Shiftキー+ALTキー if (state.WithShift && state.WithAlt) { // F10キー if (state.Key == Keys.F10) { // 矩形指定→Bitmap this.CaptureImage(CaptureTarget.RectArea, CaptureType.Bitmap); } // F11キー else if (state.Key == Keys.F11) { // アクティブウィンドウ→Bitmap this.CaptureImage(CaptureTarget.ActiveWindow, CaptureType.Bitmap); } // F12キー else if (state.Key == Keys.F12) { // デスクトップ→Bitmap this.CaptureImage(CaptureTarget.Desktop, CaptureType.Bitmap); } } // Shiftキー else if (state.WithShift) { // F10キー if (state.Key == Keys.F10) { // 矩形指定→クリップボード this.CaptureImage(CaptureTarget.RectArea, CaptureType.Clipboard); } // F11キー else if (state.Key == Keys.F11) { // アクティブウィンドウ→クリップボード this.CaptureImage(CaptureTarget.ActiveWindow, CaptureType.Clipboard); } // F12キー else if (state.Key == Keys.F12) { // デスクトップ→クリップボード this.CaptureImage(CaptureTarget.Desktop, CaptureType.Clipboard); } } // ALTキー else if (state.WithAlt) { // F10キー if (state.Key == Keys.F10) { // 矩形指定→PNG this.CaptureImage(CaptureTarget.RectArea, CaptureType.Png); } // F11キー else if (state.Key == Keys.F11) { // アクティブウィンドウ→PNG this.CaptureImage(CaptureTarget.ActiveWindow, CaptureType.Png); } // F12キー else if (state.Key == Keys.F12) { // デスクトップ→PNG this.CaptureImage(CaptureTarget.Desktop, CaptureType.Png); } } } }