Beispiel #1
0
        private void init()
        {
            keysDown = new ConcurrentDictionary <Keys, byte>();
            chivato  = new Thread(
                () =>
            {
                do
                {
                    Thread.Sleep(1);
                    POINT oldCurrentPos = currentPos;
                    //GetCursorPos(out currentPos);
                    currentPos = System.Windows.Forms.Cursor.Position;
                    if (!oldCurrentPos.Equals(currentPos))
                    {
                        INPUT input = action.createInput(currentPos, MouseFlags.MOUSEEVENTF_MOVE);
                        this.createThreadEvent(this.escuchador.onMouseMove, this, input.data.mouse).Start();
                        Console.WriteLine(currentPos);
                    }

                    byte bit = new byte();

                    if (GetAsyncKeyState(Keys.LButton) != 0)     //PRESSED
                    {
                        if (keysDown.TryAdd(Keys.LButton, bit))
                        {
                            INPUT input = action.createInput(currentPos, MouseFlags.MOUSEEVENTF_LEFTDOWN);
                            this.createThreadEvent(this.escuchador.onLeftMouseButtonDown, this, input.data.mouse).Start();
                        }
                    }
                    else if (keysDown.TryRemove(Keys.LButton, out bit))    //NOT PRESED
                    {
                        INPUT input = action.createInput(currentPos, MouseFlags.MOUSEEVENTF_LEFTUP);
                        this.createThreadEvent(this.escuchador.onLeftMouseButtonUp, this, input.data.mouse).Start();
                    }
                    /////////////////////////////////////////////////////////////////////////////////////////
                    if (GetAsyncKeyState(Keys.RButton) != 0)     //PRESSED
                    {
                        if (keysDown.TryAdd(Keys.RButton, bit))
                        {
                            INPUT input = action.createInput(currentPos, MouseFlags.MOUSEEVENTF_RIGHTDOWN);
                            this.createThreadEvent(this.escuchador.onRightMouseButtonDown, this, input.data.mouse).Start();
                        }
                    }
                    else if (keysDown.TryRemove(Keys.RButton, out bit))    //NOT PRESSED
                    {
                        INPUT input = action.createInput(currentPos, MouseFlags.MOUSEEVENTF_RIGHTUP);
                        this.createThreadEvent(this.escuchador.onRightMouseButtonUp, this, input.data.mouse).Start();
                    }
                    /////////////////////////////////////////////////////////////////////////////////////////
                    if (GetAsyncKeyState(Keys.MButton) != 0)     //PRESSED
                    {
                        if (keysDown.TryAdd(Keys.MButton, bit))
                        {
                            INPUT input = action.createInput(currentPos, MouseFlags.MOUSEEVENTF_MIDDLEDOWN);
                            this.createThreadEvent(this.escuchador.onMiddleMouseButtonDown, this, input.data.mouse).Start();
                        }
                    }
                    else if (keysDown.TryRemove(Keys.MButton, out bit))     //NOT PRESSED
                    {
                        INPUT input = action.createInput(currentPos, MouseFlags.MOUSEEVENTF_MIDDLEUP);
                        this.createThreadEvent(this.escuchador.onMiddleMouseButtonUp, this, input.data.mouse).Start();
                    }

                    //////////////////////////////////////////////////////////////////////////////////////////////
                } while (working);
            }
                );
            chivato.SetApartmentState(ApartmentState.MTA);
            chivato.IsBackground   = true;
            chivato.CurrentCulture = System.Globalization.CultureInfo.CurrentCulture;
            chivato.Priority       = ThreadPriority.Highest;
            chivato.Name           = "UMouseWorkerThread";
        }