コード例 #1
0
ファイル: Form2.cs プロジェクト: jd1015/rhododendronkiusianum
 private void keyboardHook1_KeyboardHooked(object sender, HongliangSoft.Utilities.Gui.KeyboardHookedEventArgs e)
 {
     if (e.AltDown && (e.UpDown.ToString().Equals("Down") && "F12".Equals(e.KeyCode.ToString())))
     {
         // 測定開始
         button1_Click(null, null);
     }
     if (e.AltDown && (e.UpDown.ToString().Equals("Down") && "F9".Equals(e.KeyCode.ToString())))
     {
         // 保存
         WiteFile();
         button2_Click(null, null);
     }
     if (e.AltDown && (e.UpDown.ToString().Equals("Down") && "F8".Equals(e.KeyCode.ToString())))
     {
         // 今までの時間を表示
         label1.Text = Properties.Settings.Default.ひまんちゅたいむ.ToString();
     }
     if (e.AltDown && (e.UpDown.ToString().Equals("Down") && "F7".Equals(e.KeyCode.ToString())))
     {
         // 今の測定時間を表示
         label1.Text = myStopWatch.Elapsed.ToString();
     }
     if (e.AltDown && (e.UpDown.ToString().Equals("Down") && "F6".Equals(e.KeyCode.ToString())))
     {
         // 隠す
         Hide();
     }
     if (e.AltDown && (e.UpDown.ToString().Equals("Down") && "F5".Equals(e.KeyCode.ToString())))
     {
         // 見せる
         Show();
     }
 }
コード例 #2
0
        private void keyboardHook1_KeyboardHooked(object sender, HongliangSoft.Utilities.Gui.KeyboardHookedEventArgs e)
        {
            //デバッグで実行するには デバッグ VS ホスティングプロセスを有効にする のチェックを外す
            if (e.KeyCode == this.PopupShortcutKey ||
                (this.PopupShortcutKeySub.HasValue == true && e.KeyCode == this.PopupShortcutKeySub.Value)
                )
            {
                if (e.UpDown == HongliangSoft.Utilities.Gui.KeyboardUpDown.Down)
                {
                    up_time = DateTime.Now;
                }
                else if (e.UpDown == HongliangSoft.Utilities.Gui.KeyboardUpDown.Up)
                {
                    DateTime now = DateTime.Now;

                    TimeSpan ts = now - up_time;
                    //down upの時間(押しっぱなしの場合は無視する) doubleClickTimeの流用は微妙かも・・
                    if (ts.TotalMilliseconds > doubleClickTime)
                    {
                        return;
                    }

                    //左ShiftKey ダブルクリック
                    ts        = now - prev_time;
                    prev_time = now;

                    if (ts.TotalMilliseconds <= doubleClickTime)
                    {
                        //すでに開いている場合は無視
                        if (isContextMenuStripOpen == true)
                        {
                            return;
                        }

                        //フォーカス位置の取得
                        this.ForehWnd = APIList.GetForegroundWindow();
                        var   current = APIList.GetCurrentThreadId();
                        var   target  = APIList.GetWindowThreadProcessId(this.ForehWnd, IntPtr.Zero);
                        Point p;
                        APIList.AttachThreadInput(current, target, true);
                        APIList.GetCaretPos(out p);
                        var fWnd = APIList.GetFocus();
                        APIList.ClientToScreen(fWnd, out p);
                        APIList.AttachThreadInput(current, target, false);

                        //ダブルクリック処理
                        var task = Task.Factory.StartNew(
                            () =>
                        {
                            this.Invoke(
                                (MethodInvoker)(() =>
                            {
                                Thread.Sleep(200);

                                //APIList.SetTopMost(this.Handle);
                                this.contextMenuStrip1.Show(p.X, p.Y);

                                this.contextMenuStrip1.Focus();
                                APIList.SetForegroundWindow(this.contextMenuStrip1.Handle);

                                if (this.contextMenuStrip1.Items.Count > 0)
                                {
                                    this.contextMenuStrip1.Items[0].Select();
                                }
                            }
                                                )
                                );
                        }
                            );
                    }
                }
            }
            else if (e.UpDown == HongliangSoft.Utilities.Gui.KeyboardUpDown.Up && e.KeyCode == Keys.Escape)
            {
                //キャンセルの処理
                if (isContextMenuStripOpen == true)
                {
                    this.contextMenuStrip1.Close();
                }
            }
            else
            {
                //ダブルクリックの間に違うキーが押された場合は一旦キャンセル
                up_time = DateTime.MinValue;
            }
        }