I want to know if there's something similar to SendKeys.Send("test text {sleep 250} another test text"); in C#.
I know I can use Thread.Sleep but I get the string from the user input, and I won't be able to know how many times I have to sleep.
I don't believe there is a way to have SendKeys.Send() pause mid string.
If your reading the string to send from user input, you'd be better off parsing this string into a list of partial strings to send and pause between.
i.e. using your example, you'd have a list of strings: "text text "," another test test"
and a list of sleep intervals:250
The list of sleep intervals would naturally always be 1 item shorter than the list of string to send.
Related
So what I'm trying to do is that I want my bot to be able to have two different parameters. Like what I mean is something like I can extract like a certain part of it and then after there's a "," or another symbol I can extract the following separately. So I get two different strings from one input. So like I have two strings and I want one of them to be the first half and the second one to be the rest. And I am not planning on updating to 1.0 so tell me if it's not possible in 0.9.6.
Your question isn't very clear but I think I know what you are looking for. This is a general answer for C# as I don't know how the Discord interface differs. You seem to be taking input in the form of a string, for example: play *songname*,*channelname*. To split this string into two inputs you want to use String.Split(',')
An example would be this:
string stringTakenFromDiscord = "play *songname*,*channelname*";
String[] input = stringTakenFromDiscord.Split(',');
//input[0] will be equal to what comes before the comma
//if you were to print it, it would be "play *songname*"
//input[1] will be what comes after the comma
//if you were to print it, it would be "*channelname*"
Now you can do anything you want with either of the values of the array input[] and feed them through your code to parse them. Do note that when it splits by the character, the character won't appear in either of the output strings. This will only work for inputs that only have one instance of your chosen character. You can change the character to whatever you want.
It occurs to me that it might be easier to just take the input on two separate lines instead.
I have a c# program and am trying to call a messageBox with a specific string(normal string, nothing special), And when reaching a variable to concatenate with the string, it apparently stops the concatenation.
The code:
string first = userInfo.info.getFirst(); //Some function
string last = userInfo.info.getLast(); // Some function
string message = first + "_" + last + " !";
MessageBox.Show(message);
// Output will be "(first value)";
I did try to debug and the values of "first" and "last" are correct and fine.
I also analyzed to see if any CPU or Memory peak occur(using VS's tools), but seen none.
Any idea as for the problem?
Thanks a lot!
The Win32 GUI libraries terminate strings if they find a \0 character (U+0000, Unicode "null") in them. For example, if you had:
MessageBox.Show("First part\0Second part");
then only First part would be displayed.
There are at least two options here:
Work out where the "bad" character is coming from. It's often a misuse of the Stream or TextReader API, not paying attention to how many bytes or characters are returned by a Read call
Just remove the "bad" character, e.g. message = message.Replace("\0", "");
The first option is preferable - I'd only resort to the second if I really couldn't get clean data.
I've looked online for this but not been able to find an answer unfortunately (sorry if there is something I have missed).
I have some code which filters out a specific string (which can change depending on what is read from the serial port). I want to be able to delete all of the characters which I am not using.
e.g. the string I want from the text below is "ThisIsTheStringIWant"
efefhokiehfdThisIsTheStringIWantcbunlokew
Now, I already have a function with some code which will identify this and print it to where I want. However, as the comms could be coming in from multiple ports at any frequency, before printing the string to where I want it, I need to have a piece of code which will recognise everything I don't want and delete it from my buffer.
e.g. Using the same random text above, I want to get rid of the two random strings at the ends (which are before and after "ThisIsTheStringIWant" in the middle).
efefhokiehfdThisIsTheStringIWantcbunlokew
I have tried using the highest voted answer from this question, however I can't find a way to delete the unwanted text before my wanted string. Remove characters after specific character in string, then remove substring?
If anyone can help, that would be great!
Thanks!
Edit:
Sorry, I should have probably made my question clearer.
Any possible number of characters could be before and/or after the actual string I want, and as the string I want is coming from a serial port it will be different every time depending on what comms are coming in from the serial port. On my application I have a cell in a DGV called "Extract" and by typing in the first bit of the comms I am expecting (in this case, the extract would be This). But that will be different depending on what I am doing.
Find the position of the string you want, delete from the beginning to the predecessor of that position, then delete everything from the length of your string to the end.
String: efefhokiehfdThisIsTheStringIWantcbunlokew
Step 1 - "ThisIsTheStringIWant" starts at position 13, so delete the first twelve, leaving...
String: ThisIsTheStringIWantcbunlokew
Step 2 - "ThisIsTheStringIWant" is 20 characters long, so delete from character 21 to the length of the string, leaving:
String: ThisIsTheStringIWant
I'm trying to take a string from a textbox that a user inputs into and have a keystroke for each char in that string.
SendKeys.Send("{SHIFT}{ENTER} " + text);
This does not work, I also tried to run a for loop to output each char but couldn't really get it to work.
Any thoughts?
the correct syntax for sending Shift+Enter is:
SendKeys.Send("+{ENTER}");
I think you should try:
foreach(var i in text)
SendKeys.Send("+{ENTER}("+i+")");
Note that I can not understand why you are trying to press 3 keys simultaneously. If you are trying to send shift+enter and then a char:
foreach(var i in text)
SendKeys.Send("+{ENTER}{"+i+"}");
i have been using SendKeys.SendWait("insert letter here"); to send a letter to an all ready focused application. This works fine. I have aldo been using it like SendKeys.SendWait(letterstosend); to send a string with only letters in. I notice however it wont send a tring that has both letters and numbers in. It focuses the application but sends nothing.
Can anyone advise on how to write a loop to read the first letter in a string and then send it with the SendKeys.SendWait command and then read the second letter and send that etc for thw whole string?
Thanks
SendKeys should definitely handle multiple letters well, however, if you want to send each character you can solve it like this:
string text = "abc123";
foreach(char c in text)
SendKeys.SendWait(c.ToString());
Note that there are several special characters in SendKeys that you might have to escape for this to work properly. More info on MSDN.
This might also have been the problem why your original approach failed.