Someone told me he needs a program to type names in a textbox from another application. I am not able to get an API from the application. He has to type names which are listed in an excel file. After each name he has to press enter to create something similar to tags in YouTube or stackoverflow.
There is no other way than doing it like this unless if there is any sort of code I do not know about. That's why I am asking for help.
I have considered taking a look at these but no answer was a solution.
Why does SendKey.Send() only work once in a while? --> The appsetting is added to the config file.
SendKey.Send() Not working --> I have to type variables
I succeeded in creating this application. I tested it on both my laptop and my desktop. It works on both. It also works on a laptop of a family member. This family member is a regular computer user who does not code anything.
Goal of program:
Type names which are listed in an excel file and separate them with any value into another application/site.
For example:
Values:
Jones
Holmes
Jonhson
Potter
Separation value = ";"
Output:
Jones;Holmes;Jonhson;Potter
The problem is:
The application does not work on random computers (laptops and deskops). The application works untill it has to execute the SendKey.Send command. But after a few seconds the application confirms that the entire process has been executed. This confirmation is hardcoded in my application with a messagebox. Right before the confirmation it only types the first character of the first name.
All the mentioned computers are windows 10. I have tried it with both SendKeys.Send and SendKeys.SendWait.
Thanks in advance for your help!
The code: (triggered by a simple button click)
List<string> Values = new List<string>(); //These are set by another method --> it's not empty and works fine
string Split = string.Empty;
switch (strSplitValue)
{
case "ENTER":
Split = "";
break;
case "SPATIE":
Split = " ";
break;
case ",":
Split = ", ";
break;
case ";":
Split = ";";
break;
case "/":
Split = "/";
break;
case "\\":
Split = "\\";
break;
default:
Split = strSplitValue;
break;
}
//A messagebox pops up here to clarify that the user has 8s to click with the mouse on the place where the application has to type its values. After pessed ok, it goes on.
//This messagebox always works. The program fails from the moment it executes SendKeys.Send
try {
foreach (string x in Values)
{
string strSendkeys = x + Split;
SendKeys.Send(strSendkeys);
if (strSplitValue == "ENTER")
{
Thread.Sleep(1200);
SendKeys.Send("{ENTER}");
Thread.Sleep(200);
}
}
MessageBox.Show("Task succeeded!", "Succeeded!", MessageBoxButtons.OK, MessageBoxIcon.Information);
}
catch {
MessageBox.Show("Something went wrong.");
}