Ejemplo n.º 1
0
 public void Dispose()
 {
     if (_lowLevelKeyboardHook != null)
     {
         _lowLevelKeyboardHook.Dispose();
     }
 }
        public void DisposeWhenNotActivatedTest()
        {
            var hook = new LowLevelKeyboardHook((evnt, data) => { return(LowLevelKeyboardHook.Result.Transfer); });

            Assert.IsFalse(hook.IsActivated);
            hook.Dispose();
            Assert.IsFalse(hook.IsActivated);
        }
Ejemplo n.º 3
0
        static void Main(string[] args)
        {
            TestFilter();

            return;

            // creates a new instance to capture inputs
            // also provides IsPressed, WasPressed and GetState methods
            var inputManager = new InputManager();

            // you may not need those when you use InputManager
            var keyboardHook = new LowLevelKeyboardHook();
            var mouseHook    = new LowLevelMouseHook();

            // subscribe to the events offered by InputManager
            inputManager.OnKeyboardEvent += InputManager_OnKeyboardEvent;
            inputManager.OnMouseEvent    += InputManager_OnMouseEvent;

            // same events as above (in case you only need a specific hook and less functionality)
            keyboardHook.OnKeyboardEvent += KeyboardHook_OnKeyboardEvent;
            mouseHook.OnMouseEvent       += MouseHook_OnMouseEvent;

            // we need to initialize our classes before they fire events and are completely usable
            inputManager.Initialize();
            keyboardHook.InstallHook();
            mouseHook.InstallHook();

            // registers an event (callback) which gets fired whenever the key changes it's state
            // be sure to use this method after the InputManager is initialized
            inputManager.RegisterEvent(VirtualKeyCode.Lbutton, InputManager_KeyStateChanged);

            Console.WriteLine("Waiting for up arrow key to exit!");

            // This method will block the current thread until the up arrow key changes it's state to Down
            // There is no performance penalty (spinning loop waiting for this)
            inputManager.WaitForEvent(VirtualKeyCode.Up, KeyState.Down);

            // be sure to dispose instances you dont use anymore
            // not doing so may block windows input and let inputs appear delayed or lagging
            // these classes try dispose itself when an unhandled exception occurs or the process exits
            mouseHook.Dispose();
            keyboardHook.Dispose();
            inputManager.Dispose();
        }
Ejemplo n.º 4
0
        /// <summary>
        /// Releases unmanaged and - optionally - managed resources.
        /// </summary>
        /// <param name="disposing">
        /// <c>true</c> to release both managed and unmanaged resources; <c>false</c> to release only
        /// unmanaged resources.
        /// </param>
        protected virtual void Dispose(bool disposing)
        {
            if (!disposedValue)
            {
                if (disposing)
                {
                    if (keyboardHook != null)
                    {
                        keyboardHook.Dispose();
                    }
                    if (mouseHook != null)
                    {
                        mouseHook.Dispose();
                    }

                    mapKeyState       = null;
                    singleKeyCallback = null;
                }

                disposedValue = true;
            }
        }
Ejemplo n.º 5
0
 public void Dispose()
 {
     keyboardHook.Dispose();
     inputManager.Dispose();
 }