public override void Stop() { SF = null; // Don't leave any keys pressed for (int i = 1; i < MyKeyDown.Length; i++) { if (MyKeyDown[i]) { KeyOrButtonUp(i); } } if (KeyboardDevice != null) { KeyboardDevice.Unacquire(); KeyboardDevice.Dispose(); KeyboardDevice = null; } if (mouseDevice != null) { mouseDevice.Unacquire(); mouseDevice.Dispose(); mouseDevice = null; } if (DirectInputInstance != null) { DirectInputInstance.Dispose(); DirectInputInstance = null; } }
public override void DoBeforeNextExecute() { KeyboardDevice.GetCurrentState(ref KeyState); if (Wheelturn != 0) { setPressedStrategy.Add(Wheelturn < 0 ? (int)Mouse.WheelBwd : (int)Mouse.WheelFwd); Wheelturn = Wheelturn - Math.Sign(Wheelturn); } if (Tempo != null && Tempo[0].GetLapse() >= Tempo[1]) { Tempo[0] = StopTimer(); Tempo = null; foreach (var code in Codes.Reverse()) { KeyOrButtonUp(code); } Codes = null; } setPressedStrategy.Do(); CheckScriptTimer(); if ((cmd == 'I') && setPressedStrategy.IsListEmpty()) { if (SF == null) { SF = new ScriptKeyboardAndMouse(this); } SF.KeyboardAndMouse(); } // If a mouse command was given in the script, issue it all at once right here if ((int)deltaXOut != 0 || (int)deltaYOut != 0 || wheel != 0) { var input = new MouseKeyIO.INPUT[1]; input[0].type = MouseKeyIO.INPUT_MOUSE; input[0].mi = MouseInput((int)deltaXOut, (int)deltaYOut, (uint)wheel, 0, MouseKeyIO.MOUSEEVENTF_MOVE | MouseKeyIO.MOUSEEVENTF_WHEEL); MouseKeyIO.NativeMethods.SendInput(1, input, Marshal.SizeOf(input[0].GetType())); // Reset the mouse values if ((int)deltaXOut != 0) { deltaXOut = deltaXOut - (int)deltaXOut; } if ((int)deltaYOut != 0) { deltaYOut = deltaYOut - (int)deltaYOut; } wheel = 0; } currentMouseState = null; // flush the mouse state }