3
我創建了一個程序,通過使用SendKeys命令自動爲我輸入文本。當我按下開始按鈕時,文本將按照它的樣式輸入,而當我按下開始按鈕時,文本將停止輸入。打字是通過使用間隔計時器來完成的,該間隔計時器將決定何時開始打字並在輸入2行之間有一個簡短的空間。重置SendKeys消息
問題是,當我開始鍵入並鍵入消息的一部分,然後按程序之前按停止可鍵入整個消息,然後再次鍵入,消息將繼續鍵入從停止的位置。例如,我想輸入消息「123456789」。我開始輸入程序類型「1234」,然後按停止,程序將不再輸入。然後當我再次按開始時,程序應該從1開始鍵入,但是我的程序類型爲「56789」。
如何在停止時重置線路,然後重新開始?我嘗試將消息作爲「消息」變量,當我按下停止按鈕時該消息被重置,但它不起作用。
這是我設置爲輸入的每個時間間隔打勾:
private void Space(object sender, EventArgs e)
{
if (cbRandomLine.Checked || tickCount < lbMessage.Items.Count)
{
var index = cbRandomLine.Checked ? randomLine : tickCount;
var item = lbMessage.Items[index].ToString();
SendKeys.Send(item.Substring(currentChar++, 1));
if (currentChar == item.Length)
{
SendKeys.Send("{enter}");
tmrSpace.Enabled = false;
currentChar = 0;
}
}
tmrSpace.Interval = random.Next(10, 100);
}
private void Delay(object sender, EventArgs e)
{
if (delayCount == 0)
{
tmrDelay.Stop();
tmrInterval.Start();
lblDelay.Text = "Typing...";
}
else lblDelay.Text = "Typing in: " + delayCount;
delayCount--;
}
// METHODS
private void WhenStarted()
{
tickCount = 0;
delayCount = 2;
lbMessage.Enabled = false;
txtMessage.Enabled = false;
if (cbDelay.Checked)
{
lblDelay.Text = "Typing...";
tmrInterval.Enabled = true;
}
else
{
lblDelay.Text = "Typing in: 3";
tmrDelay.Enabled = true;
}
cbPause.Enabled = false;
cbDelay.Enabled = false;
cbRandomLine.Enabled = false;
btnStart.Enabled = false;
btnStop.Enabled = true;
btnStop.Focus();
}
private void WhenStopped()
{
lblDelay.Text = string.Empty;
whenStart = false;
tickCount = 0;
txtMessage.Text = string.Empty;
lbMessage.Enabled = true;
txtMessage.Enabled = true;
cbPause.Enabled = true;
cbDelay.Enabled = true;
cbRandomLine.Enabled = true;
btnStart.Enabled = true;
btnStop.Enabled = false;
btnStart.Focus();
tmrDelay.Enabled = false;
tmrInterval.Enabled = false;
tmrSpace.Enabled = false;
}
private void SetInterval()
{
if (nudPlusMinus.Value == 0)
{
tmrInterval.Interval = int.Parse(nudInterval.Value.ToString());
}
else
{
tmrInterval.Interval = random.Next(int.Parse(nudInterval.Value.ToString()) - int.Parse(nudPlusMinus.Value.ToString()), int.Parse(nudInterval.Value.ToString()) + int.Parse(nudPlusMinus.Value.ToString()));
}
}
private void ListBoxContentCheck()
{
if (lbMessage.Items.Count > 0)
{
btnStart.Enabled = true;
}
else
{
btnStart.Enabled = false;
}
}
這就是它!謝謝。 – HelpNeeder 2013-05-17 20:14:34
那麼有一個快速的50 :) – AFischbein 2013-05-23 19:22:24
笑我的屁股:D BTW ... – HelpNeeder 2014-07-22 05:22:40