SendKeys.SendWait function - send special key to application - c#

I try to figure out how to send the character "^" (not the CTRL command) to a external text window.
This different codes I have tried:
SendKeys.SendWait("^");
SendKeys.SendWait("(^)");
Sendkeys.SendWait("{^}"); //This should be the right code, but it doesn't work either
None of those would type me the character "^" in a text field.
If I send normal text to the window it appears in the window. The "^" cannot be typed somehow.
I had a look in the MSDN and in the Online Help, but couldn't find anything close to that problem.
Any ideas?

To send the character "^" using SendKeys.SendWait(), you need to think about which keys you're actually pressing. On an en-US keyboard it's Shift & 6, which translates to this:
SendKeys.SendWait("+6");
So whichever key combination you use to generate the "^" character, enter those keys into the SendKeys.SendWait() call.

Related

CZ characters from keyboard Unity

I am working on a word game that can take input from the keyboard. Below is the code to detect the key
foreach(KeyCode kcode in Enum.GetValues(typeof(KeyCode)))
{
if (Input.GetKey(kcode))
Debug.Log("KeyCode down: " + kcode);
}
But this code is not taking input CZ language special characters (ě š č ř ž ý á í é ). I already switched my keyboard to the CZECH version.
Your guidance will be appreciated.
Do not use Input.GetKey for keyboard input. It is meant for reading game controls which don't change when you change the input language. To read text, use Input.inputString instead.
Since this looks like this, I assume that you "type" special characters like so "AltGr + 2" to get ě
So to get this key you need to add those two keys
if(Input.GetKey(KeyCode.AltGr) && Input.GetKey(KeyCode.Alpha2))
Debug.Log("KeyCode down: AltGr & 2 equals ě");
You need to "hardcode" for each letter unique configuration to get all special characters
EDIT
To use it like that Link from a comment - as far as Unity is considered, those buttons should be mapped to numeric alpha keys.
So using Input.GetKey(KeyCode.Alpha2) is equal to ě - but you need to write your own handler for that.

Better way to replace text in globally except using SendKeys.Send

I'm trying to create an IME (Input Method Editor) or something similar to that as helping to type ANSI local language font.
it needs to replace some characters when the user types anywhere in Windows. (Word, Photoshop Coreldraw etc.)
For example when user type "r" character and "E" character, IME need to replace "rE" with "ú". I'm using a low-level key hook to capture keypress and SendKeys.Send to replace characters.
If chkStr = "rE" Then
SendKeys.Send("{BS}") 'backspace for delete "r"
SendKeys.Send("{BS}") 'backspace for delete "E"
SendKeys.Send("ú")
End If
It works. But some applications (i.e Adobe InDesign) have inbuilt key shortcuts such as shift + backspace. when user type "e" with shift key it combine with SendKeys.Send("{BS}"). the result is it calling the key shortcut. I hope experts in here can give me a solution for it.
Thanks in advance

How to output windows Alt keycodes in a C# console app

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.

Use SendKeys with string in c#?

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.

Keyboard hook in c#

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.

Categories