Exemple #1
0
        /// <summary>
        ///     Initializes the specified capture mouse move.
        /// </summary>
        /// <param name="captureMouseMove">if set to <c>true</c> [capture mouse move].</param>
        /// <param name="clearInjectedFlag">if set to <c>true</c> [clear injected flag].</param>
        /// <exception cref="InvalidOperationException">The " + nameof(InputManager) + " is already initialized.</exception>
        public void Initialize(bool captureMouseMove, bool clearInjectedFlag)
        {
            lock (_lockObject)
            {
                if (IsInitialized)
                {
                    throw new InvalidOperationException("The " + nameof(InputManager) + " is already initialized.");
                }

                _keyStateChangedCallbacks = new Dictionary <VirtualKeyCode, List <KeyStateChangedEventHandler> >();
                _keyStates = new Dictionary <VirtualKeyCode, KeyState>();

                foreach (KeyValuePair <VirtualKeyCode, string> pair in KeyCodeConverter.EnumerateVirtualKeyCodes())
                {
                    _keyStateChangedCallbacks.Add(pair.Key, new List <KeyStateChangedEventHandler>());
                    _keyStates.Add(pair.Key, KeyState.None);
                }

                _keyboardHook = new LowLevelKeyboardHook(clearInjectedFlag);
                _mouseHook    = new LowLevelMouseHook(captureMouseMove, clearInjectedFlag);

                _keyboardHook.OnKeyboardEvent += _keyboardHook_OnKeyboardEvent;
                _mouseHook.OnMouseEvent       += _mouseHook_OnMouseEvent;

                _keyboardHook.InstallHook();
                _mouseHook.InstallHook();

                IsInitialized = true;
            }
        }
        private void Initialize(bool captureMouseMove, bool clearInjectedFlag)
        {
            // initialize vars
            lockObject = new object();

            mapKeyState = new Dictionary <VirtualKeyCode, KeyState>();

            foreach (var pair in KeyCodeConverter.EnumerateVirtualKeyCodes())
            {
                mapKeyState.Add(pair.Key, KeyState.None);
            }

            singleKeyCallback = new Dictionary <VirtualKeyCode, List <KeyStateChangedCallback> >();

            // initialize hooks
            keyboardHook = new LowLevelKeyboardHook(clearInjectedFlag);
            mouseHook    = new LowLevelMouseHook(captureMouseMove, clearInjectedFlag);

            keyboardHook.OnKeyboardEvent += KeyboardHook_OnKeyboardEvent;
            mouseHook.OnMouseEvent       += MouseHook_OnMouseEvent;

            keyboardHook.InstallHook();
            mouseHook.InstallHook();
        }