// ButtonDown and ButtonUp public void SetButtonPressed(int button, bool pressed) { if (MyKeyDown[button] == pressed) { return; } MyKeyDown[button] = pressed; uint btn_flag; int mousedata = 0; var reelbutton = button - (int)Mouse.Left; var up = !pressed ? 2 : 1; if (reelbutton == 3 || reelbutton == 4) { mousedata = reelbutton - 3 + (int)MouseKeyIO.XBUTTON1; } btn_flag = (mousedata > 0 ? MouseKeyIO.MOUSEEVENTF_XDOWN : MouseKeyIO.MOUSEEVENTF_LEFTDOWN << (reelbutton * 2)) * (uint)up; var input = new MouseKeyIO.INPUT[1]; input[0].type = MouseKeyIO.INPUT_MOUSE; input[0].mi = MouseInput(0, 0, (uint)mousedata, 0, btn_flag); MouseKeyIO.NativeMethods.SendInput(1, input, Marshal.SizeOf(input[0].GetType())); }
// KeyDown and KeyUp public void SetKeyPressed(int code, bool pressed) { if (MyKeyDown[code] == pressed || code < 1 || code > 255) { return; } MyKeyDown[code] = pressed; var input = new MouseKeyIO.INPUT[1]; input[0].type = MouseKeyIO.INPUT_KEYBOARD; if (pressed) { input[0].ki = KeyInput((ushort)code, extendedKeyMap.Contains(code) ? MouseKeyIO.KEYEVENTF_EXTENDEDKEY : 0); } else { if (extendedKeyMap.Contains(code)) { input[0].ki = KeyInput((ushort)code, MouseKeyIO.KEYEVENTF_EXTENDEDKEY | MouseKeyIO.KEYEVENTF_KEYUP); } else { input[0].ki = KeyInput((ushort)code, MouseKeyIO.KEYEVENTF_KEYUP); } } MouseKeyIO.NativeMethods.SendInput(1, input, Marshal.SizeOf(input[0].GetType())); }
public override void DoBeforeNextExecute() { KeyboardDevice.GetCurrentState(ref KeyState); if (memory != null) { KeysPressed.Clear(); for (int i = 1; i < 238; i++) { if (IsDown(i)) { KeysPressed.Add(i); } } } 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 ScriptKeyboardAndMouseA(this); } SF.KeyboardAndMouseA(); } // 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 }