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.
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'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
How can I output Windows Alt key codes to the console in a C# console app using Console.WriteLine()?
I would like to output characters such as those used for creating boxes.
I can do so manually in a command prompt by holding alt and typing in the appropriate number such as Alt+205, Alt+187, etc.
Thanks
I suppose the easiest way would be to include them directly in your string literals within your source code:
Console.WriteLine("ââ");
EDIT: I'm sorry - my answer is incorrect. ASCII.GetChars will not work for extended ASCII characters. Thanks to Douglas for correcting me.
I think Douglas's answer is the most direct, but you could also get the character based on the value directly using something like this:
char[] characters = System.Text.Encoding.ASCII.GetChars(new byte[]
{65});
For whatever ASCII code you wanted.
I want to develop a keystroke converter which will convert any keystroke into my local language. For example, if user type "a" then it will be replaced with it's corresponding unicode letter "\u0995"
I used a code similar to: https://stackoverflow.com/global-low-level-keyboard-hook-freezing-in-c-net-3-5 There, i edited as follows:
// MessageBox.Show("Test"); // I do not want this so commented
int vkCode = Marshal.ReadInt32(lParam);
Console.WriteLine((Keys)(vkCode + 2));
SendKeys.Send("mmm"); // mmm will be my desired unicode character
Now, i open any application and type anything i get both the typed letter and "mmm".
For example, if i type: abcd then i get output as: mmmcmmmdmmmemmmf .........[output]
Now my question is,
1) How can i edit this code to send a unicode letter instead of a letter ? ( I mean, if i type "p", then i want other applications should receive unicode character similar to this unicode character: "0996"
2) How to make sure only the unicode character is sent to other application, the typed character must not be appended. I mean, i don't want the unicode character and typed english letter as in the output above[output]
1) How can i edit this code to send a
unicode letter instead of a letter ?
SendKeys.Send() can send Unicode Indic characters too e.g.
SendKeys.Send("āĻ");
If you want to use Unicode code to send the character, then
SendKeys.Send('\u0996'.ToString());
2) How to make sure only the unicode
character is sent to other
application?
If the code is inside a KeyDown event function, you can suppress the actual key being typed by using following just after SendKeys.Send() statement:
e.Handled == true;
AFAIK, hooking is for monitoring, so not sure if its correct approach for what you are trying to do. But in your code, perhaps you can skip calling next hook "CallNextHookEx" and that may swallow the key typed. Mind you that you should swallow conditionally otherwise you may block keys such as ALT and CTL.
I'm not quite sure, but I think you can interrupt the chain if you don't call CallNextHookEx but return a null pointer instead. But that this is something you should rather not do usually ;)
Best Regards,
Oliver Hanappi
Skip calling CallNextHookEx to prevent a particular key event from propagating.
Re: using SendKeys to enter Unicode input: "If your application is intended for international use with a variety of keyboards, the use of Send could yield unpredictable results and should be avoided." -MSDN Basically I think SendKeys doesn't explicitly support sending Unicode input.
Have you looked at Microsoft Text Services Framework instead of this approach you are trying? I think it is basically purpose built to address what you are trying to do.
I am working with a project that includes getting MMS from a mms-gateway and storing the image on disk.
This includes using a received base64encoded string and storing it as a zip to a web server. This zip is then opened, and the image is retrieved.
We have managed to store it as a zip file, but it is corrupted and cannot be opened.
The documentation from the gateway is pretty sparse, and we have only a php example to rely on. I think we have figured out how to "translate" most of it, except for the PHP function stripcslashes(inputvalue). Can anyone shed shed any light on how to do the same thing in c#?
We are thankful for any help!
stripcslashes() looks for "\x" type elements within longer strings (where 'x' could be any character, or perhaps, more than one). If the 'x' is not recognised as meaningful, it just removes the '\' but if it does recognise it as a valid C-style escape sequence (i.e. "\n" is newline; "\t" is tab, etc.), as I understand it, the recognised character is inserted instead: \t will be replaced by a tab character (0x09, I think) in your string.
I'm not aware of any simple way to get the .net framework to do the same thing without building a similar function yourself. This obviously isn't very hard, but you need to know which escape sequences to process.
If you happen to know (or find out by inspecting your base64 text) that the only thing in your input that will need processing is a particular one or two sequences (say, tab characters), it becomes very easy and the following snippet shows use of String.Replace():
string input = #"Some\thing"; // '#' means string stored without processing '\t'
Console.WriteLine(input);
string output = input.Replace(#"\t", "\t");
Console.WriteLine(output);
Of course, if you really do simply want to remove all the slashes:
string output = input.Replace(#"\", "");