示例#1
0
        private void RunDriverThread()
        {
            //create and init
            _rmInput = new RawMouseInput();
            if (_rmInput == null)
            {
                MessageBox.Show("ERROR: could not create rawinput class");
            }

            _driverWindow = new DriverWindow(_rmInput);
            if (_driverWindow == null)
            {
                MessageBox.Show("ERROR: could not create driverwindow class");//error
            }

            _rmInput.RegisterForWM_INPUT(_driverWindow.Handle);
            _filter = new PreMessageFilter();
            if (_filter == null)
            {
                MessageBox.Show("ERROR: could not add premessage filter"); //error
            }

            Application.AddMessageFilter(_filter);
            Application.Run(_driverWindow);
            Application.RemoveMessageFilter(_filter);

            if (_driverWindow.IsDisposed == false)
            {
                _driverWindow.Dispose();
            }
            _driverWindow = null;
            _rmInput      = null;
        }
        private void RegisterMice()
        {
            rawMouseInput = new RawMouseInput();
            rawMouseInput.RegisterForWM_INPUT(System.Windows.Forms.Control.FromHandle(Game1.game1.Window.Handle).FindForm().Handle);            //form.handle
            System.Windows.Forms.Application.AddMessageFilter(new PreMessageFilter());

            foreach (object rawMouseObj in rawMouseInput.Mice)
            {
                if (rawMouseObj != null)
                {
                    mice.Add((RawMouse)rawMouseObj);
                }
            }
            Console.WriteLine($"Registered mouse driver, found {mice.Count} mice");
        }
示例#3
0
        /// <summary>
        /// Create a new driverwindow and register that window to receive WM_INPUT messages from RawMouseInput
        /// </summary>
        private void RunDriverThread()
        {
            // Create and initialise array of all rawmice
            _rmInput = new RawMouseInput();
            if (_rmInput == null)
            {
                MessageBox.Show("ERROR: could not create rawinput class");
            }

            // Create driver window to receive WM_INPUT messages
            try {
                _driverWindow = new InputCaptureWindow(_rmInput);
            }
            catch (Exception e) {; }

            if (_driverWindow == null)
            {
                MessageBox.Show("ERROR: could not create driverwindow class");
            }

            // Register the window to receive raw input
            _rmInput.RegisterForWM_INPUT(_driverWindow.Handle);

            // Create a message filter
            _filter = new PreMessageFilter();
            if (_filter == null)
            {
                MessageBox.Show("ERROR: could not add premessage filter");
            }

            // Apply the filter
            Application.AddMessageFilter(_filter);

            // Load the form and begin the main message pump loop
            Application.Run(_driverWindow);

            // FOLLOWING LINES ONLY EXECUTE WHEN driverWindow EXITS!
            // Remove the message filter
            Application.RemoveMessageFilter(_filter);

            // Clean up
            if (_driverWindow.IsDisposed == false)
            {
                _driverWindow.Dispose();
            }
            _driverWindow = null;
            _rmInput      = null;
        }
        public void RegisterMice()
        {
            if (hasRegistered)
            {
                return;
            }
            hasRegistered = true;

            rawMouseInput = new RawMouseInput();
            rawMouseInput.RegisterForWM_INPUT(System.Windows.Forms.Control.FromHandle(Terraria.Main.instance.Window.Handle).FindForm().Handle);            //form.handle
            System.Windows.Forms.Application.AddMessageFilter(new PreMessageFilter());

            foreach (object rawMouseObj in rawMouseInput.Mice)
            {
                if (rawMouseObj != null)
                {
                    mice.Add((RawMouse)rawMouseObj);
                }
            }
            Console.WriteLine($"Registered mouse driver, found {mice.Count} mice");
        }