private void button3_Click(object sender, EventArgs e) { InputBuilder inb = new InputBuilder(); inb.AddKeyDown(Keys.LShiftKey); inb.AddKeyUp(Keys.ShiftKey); InputSender.DispatchInput(inb.ToArray()); }
static void eventsender() { while (true) { lock (bufferlock) { if (input_queue.Count == 0) { Monitor.Wait(bufferlock); // Release and wait to be pulsed so we can re-acquire. } output_queue.AddRange(input_queue); input_queue.Clear(); } // Flush the output queue while (output_queue.Count != 0) { // If the KeyUp bit is not set, then this is a KeyDown event. bool isDown = (output_queue[0].Data.Keyboard.Flags & (uint)KeyboardFlag.KeyUp) == 0; // If the last event was > 200ms ago, we dispatch the event immediately. if (lastEventTimer.ElapsedMilliseconds < 200) { // Perform the delay AccurateTimer.AccurateSleep(isDown ? RandSleepDown() : RandSleepUp()); // Todo - maybe dont delay the up events huh } // Dispatch the event actually now InputSender.DispatchInput(new INPUT[] { output_queue[0] }); // Remove this ( we should really use a queue because this has to shift all those elements over ) output_queue.RemoveAt(0); // Restart the 'last event timer' lastEventTimer.Restart(); } } }