예제 #1
0
        /// <summary>
        /// キーアップ時に呼ばれる
        /// 該当するキーの押下フラグをfalseにする
        /// また、マウス操作もキーアップをトリガーとして発動させるようにする
        /// </summary>
        /// <param name="e"> 離されたキー情報 </param>
        internal void KeyupEvent(KeyboardHookedEventArgs e)
        {
            if (e.ExtraInfo != (int)Key.EXTRA_INFO)
            {
                _enablekeyF[(byte)e.KeyCode] = false;
                _enablekeyE[(byte)e.KeyCode] = false;
                foreach (var m in this._mass.Mice.Where(m => !m.Push.Any(k => !_enablekeyE[k] && k != (byte)e.KeyCode)))
                {
                    if (this._mouseTask?.Status == TaskStatus.Running)
                    {
                        if (Properties.Settings.Default.mouseReClick == 0)
                        {
                            return;
                        }
                        else
                        {
                            this._mouseTaskCancelToken.Cancel();
                            while (this._mouseTask?.Status == TaskStatus.Running)
                            {
                            }
                        }
                    }
                    //スイッチの状態によって、操作する/しないを判定する
                    if (m.mouseData.SwitchState != SwitchingStyle.BOTH && m.mouseData.SwitchState != Client.SwitchState)
                    {
                        continue;
                    }
                    this._mouseTaskCancelToken = new CancellationTokenSource();
                    this._mouseTask            = Task.Run(() => {
                        foreach (var send in m.mouseData.Value)
                        {
                            if (this._mouseTaskCancelToken.Token.IsCancellationRequested)
                            {
                                throw new TaskCanceledException();
                            }
                            var x = Client.x + (int)Math.Round(send.x * Client.ratioW);
                            var y = Client.y + (int)Math.Round(send.y * Client.ratioH);
                            switch (send.op)
                            {
                            case Operation.LEFT:
                                Win32.Mouse.SetCursorPos(x, y);
                                Click.Left(x, y, send.sleepBetween);
                                break;

                            case Operation.RIGHT:
                                Win32.Mouse.SetCursorPos(x, y);
                                Click.Right(x, y, send.sleepBetween);
                                break;

                            case Operation.MOVE:
                                Win32.Mouse.SetCursorPos(x, y);
                                break;

                            default:
                                throw new ArgumentOutOfRangeException();
                            }
                            if (this._mouseTaskCancelToken.Token.IsCancellationRequested)
                            {
                                throw new TaskCanceledException();
                            }
                            Thread.Sleep(send.sleepAfter);
                        }
                    }, this._mouseTaskCancelToken.Token);
                }
            }
        }