Simulate barcode

Date: 2023-04-14

https://github.com/mroach/barcode-simulator

using System;
using System.ComponentModel;
using System.Diagnostics;
using System.Linq;
using System.Threading;
using System.Windows.Forms;

// System.Windows.Forms.SendKeys

// do the delayed key sending in a separate thread so we don't hang the window
ThreadStart starter = () => StartSending(s, 10, endKey);
var t = new Thread(starter) { Name = "Sending keys " + s };
t.Start();


private static void StartSending(string text, int delay, Keys endKey = Keys.None)
{
	foreach (var s in text.Select(character => character.ToString()))
	{
		Debug.WriteLine("{0} Sending text '{1}'", DateTime.Now.ToString("HH:mm:ss.fff"), s);
		SendKeys.SendWait(s);
		SendKeys.Flush();
		Thread.Sleep(delay);
	}

	// if configured, send an 'end' key to signal that we're at the end of the barcode
	if (endKey != Keys.None)
		SendKeys.SendWait("{" + Enum.GetName(typeof (Keys), endKey) + "}");

	// beep!
	System.Media.SystemSounds.Beep.Play();
}
76750cookie-checkSimulate barcode