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.
Related
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
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.
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'm facing a simple problem that bugs me...
I have a MaskedTextBox and I want the user to be able to enter 3 numbers at the end :
"My Masked Text Box : XXX"
This text will be translated. The problem is, this control uses Microsoft's recipe to validate the input and in this example, the final display will look like this :
"My M_sked Text Box : _"
The letter 'a' is considered like a control caracter instead of a simple text caracter. I can backslash it but when the text is translated I have to do it again and I think it's ridiculous to have to do something like that...
I hope I'm being clear...
Thanks in advance for your help !
The 'a' needs to be quoted as a literal. The Mask should be something like:
My M\asked Text Box : 000
You should use '9' rather than '0' as the placeholder for an optional numerical character.
Of course any other of the characters that match mask options should be 'literal' too.
http://msdn.microsoft.com/en-us/library/system.windows.forms.maskedtextbox.mask.aspx
After reading the comments I'd like to add another suggestion (you clearly understood about literals -- the problem is your translation.)
Would it be feasible to run the translated text strings through a filter that put literal-quotes in where possible? It's not that nice a solution, because if Microsoft added new control characters it'll break your filter, but I think it would work.
I write windows application using C# and .NET2.0.
In RichTextBox I would like to show Celsius symbol.
How to do it? Is it possible?
Do you mean Celsius symbol as in 37°C? If so you can simply put that character where it should be, I guess:
richTextBox.Text = string.Format("{0}°C", degrees);
If you are looking for character codes (or just want to find character to copy/paste them), you can use the Character Map application in Windows (in Start -> Programs -> Accessories -> System Tools).
Do you mean °C? You get ° from the keyboard as ALT + 0176 on the numeric keypad.
If you are wary of embedding a non-ASCII character in your source code, you could use the following instead:
richTextBox.Text = string.Format("{0}\u00B0C", degrees);
(B0 is the hexadecimal for 176.)
richTextBox1.Text = "°" will display a degree symbol in a rich textbox but I'm pretty sure you want something else. Please rephrase your question if that's the case.
° //html entity.