【发布时间】:2013-09-10 01:55:53
【问题描述】:
好的,我正在制作一个自动打字机,我希望用户能够输入键 {}()^+ 并输出应用程序。我知道您需要格式化 SendKeys.Send({^}); 之类的符号但我不能让它工作。到目前为止,这是我的 Timer Tick 的内容。另外,我有全局 int blockCount,它告诉程序移动到 blockText 字符串中的下一个字符。
它返回“组分隔符不平衡”。
private void timer3_Tick(object sender, EventArgs e)
{
string blockText = richTextBox1.Text;
int blockLength = richTextBox1.TextLength;
btrand = RandomNumber(75, 200); //I have a method to make a rand num
timer3.Interval = btrand;
char[] specialChars = { '{', '}', '(', ')', '+','^' };
foreach (char letter in blockText)
{
for (int i = 0; i < specialChars.Length; i++)
{
if (letter == specialChars[i])
{
SendKeys.Send("{" + specialChars[i] + "}");
blockText.Remove(blockText.IndexOf(specialChars[i].ToString()));
}
else
{
SendKeys.Send(letter.ToString());
}
}
}
blockCount++;
if (blockCount >= blockLength)
{
blockCount = 0;
}
}
【问题讨论】:
-
"cant get this to work" 是对您问题的绝对糟糕描述。
-
对不起,你的权利。它返回“组分隔符不平衡。”
-
在哪一行,使用哪个输入?
-
SendKeys 很烂。在这里查看我的答案:stackoverflow.com/a/41886193/1599699