Reputation: 175
I'm trying to make a chat spammer in a game just for practice with gui programming in C# but I ran into a problem when trying to send multiple words. I'm sending them as keystrokes because I don't know any other way that I could. Whenever I come across a space in the char array I get an ArgumentExeception saying, "Keyword ' ' is not valid."
this is the code I'm using to send the keys:
foreach (char j in text)
SendKeys.Send("{" + j + "}");
Upvotes: 0
Views: 2188
Reputation: 4308
The {'s around it are your problem. SendKeys will send text like:
SendKeys.Send("hello");
SendKeys.Send(" ");
The {'s are special. They allow for sending of special characters like the F1, F2, Page Up, Page Down. See this reference for the full list. The answer is, you don't need the {'s unless you're sending one of those special keys.
https://msdn.microsoft.com/en-us/library/system.windows.forms.sendkeys(v=vs.110).aspx
Also, if you're sending the full string of text, you don't need to send it character by character. You can just do this unless you're truly trying to simulate key strokes with it:
SendKeys.Send(text);
Upvotes: 3