Example #1
0
        //* -----------------------------------------------------------------------*
        /// <summary>フォース フィードバックの初期化をします。</summary>
        ///
        /// <param name="errorReport">追記されるエラー レポート。</param>
        /// <returns>フォース フィードバックの初期化に成功した場合、<c>true</c>。</returns>
        private bool initializeForceFeedBack(ref string errorReport)
        {
            bool   result = true;
            string enter  = Environment.NewLine;
            CooperativeLevelFlags coLevel =
                CooperativeLevelFlags.NoWindowsKey | CooperativeLevelFlags.Background;

            try
            {
                try
                {
                    device.Properties.AutoCenter = false;
                }
                catch (Exception e)
                {
                    throw new ApplicationException(Resources.INPUT_WARN_LEGACY_CENTER, e);
                }
                if (hWnd == IntPtr.Zero)
                {
                    throw new ApplicationException(Resources.INPUT_WARN_LEGACY_EXCLUSIVE);
                }
                device.SetCooperativeLevel(hWnd, CooperativeLevelFlags.Exclusive | coLevel);
            }
            catch (Exception e)
            {
                result       = false;
                errorReport += Resources.INPUT_WARN_LEGACY_COOP + enter + e.ToString();
                device.SetCooperativeLevel(null, CooperativeLevelFlags.NonExclusive | coLevel);
            }
            return(result);
        }
Example #2
0
 private Input(System.Windows.Forms.Control windowControl)
 {
     this.windowControl = windowControl;
     this.mouseLocation = new System.Drawing.Point();
     flags = CooperativeLevelFlags.Exclusive | CooperativeLevelFlags.Foreground;
     //Resume();
     //InitInputDevices();
 }
Example #3
0
        public Input(Control parent, CooperativeLevelFlags keyboardFlags, CooperativeLevelFlags mouseFlags)
        {
            keyboard = new Device(SystemGuid.Keyboard);
            keyboard.SetCooperativeLevel(parent, keyboardFlags);
            keyboard.Acquire();

            mouse = new Device(SystemGuid.Mouse);
            mouse.SetCooperativeLevel(parent, mouseFlags);
            mouse.Acquire();
        }
Example #4
0
 public void SetCooperative(CooperativeLevelFlags flags)
 {
     try
     {
         this.flags = flags;
         this.FreeDirectInput();
         this.InitInputDevices();
     }
     catch (Exception ex)
     {
         Logging.Logger.AddError("Chyba pri nastavovani CooperativeLevel \n" + ex.ToString());
     }
 }
        //* -----------------------------------------------------------------------*
        /// <summary>フォース フィードバックの初期化をします。</summary>
        ///
        /// <param name="privateMembers">
        /// オブジェクトと状態クラスのみがアクセス可能なフィールド。
        /// </param>
        /// <returns>フォース フィードバックの初期化に成功した場合、<c>true</c>。</returns>
        private bool initializeForceFeedback(
            CInputLegacy.CPrivateMembers privateMembers
            )
        {
            bool bResult = true;

            try
            {
                privateMembers.device.Properties.AutoCenter = false;
            }
            catch (Exception e)
            {
                bResult = false;
                privateMembers.errorReport +=
                    "ゲームパッドのオート・センター機能のOFFに出来ませんでした。" +
                    Environment.NewLine;
                privateMembers.errorReport +=
                    "このゲームパッドではフォース フィードバックの使用はできません。" +
                    Environment.NewLine;
                privateMembers.errorReport += e.ToString();
            }
            bool ZeroHandle = privateMembers.hWnd == IntPtr.Zero;
            CooperativeLevelFlags coLevel =
                CooperativeLevelFlags.NoWindowsKey | CooperativeLevelFlags.Background;

            try
            {
                if (!bResult || ZeroHandle)
                {
                    throw new ApplicationException(
                              "ウィンドウ ハンドルが指定されていないため、ゲームパッドを独占出来ません。");
                }
                privateMembers.device.SetCooperativeLevel(
                    privateMembers.hWnd, CooperativeLevelFlags.Exclusive | coLevel);
            }
            catch (Exception e)
            {
                bResult = false;
                privateMembers.errorReport +=
                    "ゲームパッドの独占に失敗しました。共有モードで再設定を試みます。" +
                    Environment.NewLine;
                privateMembers.errorReport +=
                    "このモードではフォースフィードバックの使用は出来ません。" +
                    Environment.NewLine;
                privateMembers.errorReport += e.ToString();
                privateMembers.device.SetCooperativeLevel(
                    null, CooperativeLevelFlags.NonExclusive | coLevel);
            }
            return(bResult);
        }
Example #6
0
        //* ────────────-_______________________*
        //* constructor & destructor ───────────────────────*

        //* -----------------------------------------------------------------------*
        /// <summary>コンストラクタ。</summary>
        ///
        /// <param name="guid">デバイスのインスタンスGUID</param>
        /// <param name="hWnd">ウィンドウ ハンドル</param>
        public CLegacyInput(Guid guid, IntPtr hWnd)
        {
            try
            {
                device = new Device(guid);
                CLogger.add("◎◎ レガシ ゲームパッド情報\r\n" + ToString());
                CooperativeLevelFlags coLevel =
                    CooperativeLevelFlags.NoWindowsKey | CooperativeLevelFlags.Background;
                device.SetDataFormat(DeviceDataFormat.Joystick);
                try
                {
                    device.Properties.AutoCenter = false;
                }
                catch (Exception e)
                {
                    CLogger.add(Resources.WARN_LEGACY_CENTER);
                    CLogger.add(e);
                    hWnd = IntPtr.Zero;
                }
                if (hWnd == IntPtr.Zero)
                {
                    device.SetCooperativeLevel(null, CooperativeLevelFlags.NonExclusive | coLevel);
                }
                else
                {
                    try
                    {
                        device.SetCooperativeLevel(hWnd, CooperativeLevelFlags.Exclusive | coLevel);
                    }
                    catch (Exception e)
                    {
                        CLogger.add(Resources.WARN_LEGACY_EXCLUSIVE);
                        CLogger.add(Resources.WARN_LEGACY_COOP);
                        CLogger.add(e);
                        hWnd = IntPtr.Zero;
                        device.SetCooperativeLevel(null, CooperativeLevelFlags.NonExclusive | coLevel);
                    }
                }
                device.Properties.AxisModeAbsolute = true;
                int[] anAxis = null;
                foreach (DeviceObjectInstance doi in device.Objects)
                {
                    if ((doi.ObjectId & (int)DeviceObjectTypeFlags.Axis) != 0)
                    {
                        device.Properties.SetRange(
                            ParameterHow.ById, doi.ObjectId, new InputRange(-1000, 1000));
                    }
                    if ((doi.Flags & (int)ObjectInstanceFlags.Actuator) != 0)
                    {
                        int[] __anAxis;
                        if (anAxis == null)
                        {
                            anAxis = new int[1];
                        }
                        else
                        {
                            __anAxis = new int[anAxis.Length + 1];
                            anAxis.CopyTo(__anAxis, 0);
                            anAxis = __anAxis;
                        }
                        anAxis[anAxis.Length - 1] = doi.Offset;
                        if (anAxis.Length == 2)
                        {
                            break;
                        }
                    }
                }
                try
                {
                    if (hWnd == IntPtr.Zero)
                    {
                        throw new UnsupportedException("共有モードではフォースフィードバックは使用は出来ません。");
                    }
                    FORCE_PATTERNS.Add(EForcePreset.Square, createEffect(anAxis, 5000, 583333));
                    FORCE_PATTERNS.Add(EForcePreset.Short, createEffect(anAxis, 5000, 0, 100000));
                    FORCE_PATTERNS.Add(EForcePreset.Mild, createEffect(anAxis, 5000, 0, 1000000));
                    FORCE_PATTERNS.Add(EForcePreset.Hard, createEffect(anAxis, 10000, 0, 2000000));
                }
                catch (Exception e)
                {
                    CLogger.add("フォース フィードバックの作成に失敗しました。");
                    CLogger.add(e);
                }
                device.Acquire();
            }
            catch (Exception e)
            {
                CLogger.add(Resources.ERR_LEGACY_INIT_FAILED);
                CLogger.add(e);
                exception = e;
                Dispose();
            }
        }
        private void AttachRecorderImpl(IntPtr window, InputRecorder recorder, CooperativeLevelFlags cooperativeLevelFlags)
        {
            if (this.running) {
                throw new InvalidOperationException("Already attached");
            }

            this.recordedSequenceQueue = new BlockingQueue<IInputSequence>();

            (this.recordingHandlerThread = new Thread(RecordingHandler) {
                Name = "Direct Input Recording Runner",
                IsBackground = true
            }).Start();

            this.recording = true;
            this.recordingHandler = recorder;

            AttachImpl(window, cooperativeLevelFlags);
        }
        private void AttachImpl(IntPtr window, CooperativeLevelFlags cooperativeLevelFlags)
        {
            if (this.running) {
                throw new InvalidOperationException("Already attached");
            }

            int index = 2;
            this.running = true;

            lock (this.syncRoot) {
                List<AutoResetEvent> resets = new List<AutoResetEvent>();
                foreach (DeviceInstance di in Manager.GetDevices(DeviceClass.GameControl, EnumDevicesFlags.AttachedOnly)) {
                    AutoResetEvent reset = new AutoResetEvent(false);

                    var d = new Device(di.InstanceGuid);
                    d.Properties.BufferSize = 10;
                    d.SetCooperativeLevel(window, cooperativeLevelFlags);
                    d.SetDataFormat(DeviceDataFormat.Joystick);
                    d.SetEventNotification(reset);
                    d.Acquire();

                    resets.Add(reset);
                    this.joysticks.Add(di.InstanceGuid, d);
                    this.joystickIndexes.Add(index++, di.InstanceGuid);
                }

                this.waits = new AutoResetEvent[this.joysticks.Count + 2];
                this.waits[0] = new AutoResetEvent(false);
                this.keyboard = new Device(SystemGuid.Keyboard);
                this.keyboard.Properties.BufferSize = 10;
                this.keyboard.SetCooperativeLevel(window, cooperativeLevelFlags);
                this.keyboard.SetDataFormat(DeviceDataFormat.Keyboard);
                this.keyboard.SetEventNotification(this.waits[0]);
                this.keyboard.Acquire();

                this.waits[1] = new AutoResetEvent(false);
                this.mouse = new Device(SystemGuid.Mouse);
                this.mouse.Properties.BufferSize = 10;
                this.mouse.SetCooperativeLevel(window, cooperativeLevelFlags);
                this.mouse.SetDataFormat(DeviceDataFormat.Mouse);
                this.mouse.SetEventNotification(this.waits[1]);
                this.mouse.Acquire();

                resets.CopyTo(this.waits, 2);
            }

            (this.inputRunnerThread = new Thread(InputRunner) {
                Name = "DirectInput Runner",
                IsBackground = true
            }).Start();
        }
Example #9
0
 public void SetCooperativeLevel(IntPtr hwnd, CooperativeLevelFlags flags)
 {
     throw new NotImplementedException();
 }
Example #10
0
 public void SetCooperativeLevel(Control parent, CooperativeLevelFlags flags)
 {
     throw new NotImplementedException();
 }