Skype:TextControlSupport
Orders:877-462-4772
TX Text Control - word processing components.
« »

Insert special characters using the modifier keys

Blogged by Björn Meyer on October 30, 2008 and tagged with AltGr, Keystrokes, .NET.

The modifier key AltGr is commonly used to insert special characters or currency symbols. In some languages, it is used to insert accented characters.

By default, TX Text Control implements the functionality of the CTRL modifier on the AltGr key as well. To implement the language specific functionality, you need to cancel the TX Text Control handling by trapping the keystrokes.

As an example, the following code shows how to implement the Polish special characters ż and ź that are inserted when pressing AltGr+Z and AltGr+X:

private void textControl1_KeyDown(object sender, KeyEventArgs e)
{
  if (e.Modifiers == (Keys.Alt | Keys.Control))
  {
    switch(e.KeyCode)
    {
      case Keys.Z:
        textControl1.Selection.Text = "ż";
        break;
      case Keys.X:
        textControl1.Selection.Text = "ź";
        break;
     }

     e.Handled = true;
  }
}

More about the different implementations of the AltGr key can be found here:

Wikipedia: AltGr key

« Prev:Chinese resources available for TX Text Control .NET 14.0
» Next:Strong name your language resource files

Comments

If you would like to comment on this blog entry, please post a comment.

Posted by Brian Seekford on Friday, October 31, 2008 at 13:40:47:

Good morning,

The code actually has some buggy issues causing the characters to double up and doesn't account for non-polish keyboards.

Here is code that does work:

if ((InputLanguage.CurrentInputLanguage.Equals(InputLanguage.FromCulture(CultureInfo.GetCultureInfo("pl")))) ||
(InputLanguage.CurrentInputLanguage.Equals(InputLanguage.FromCulture(CultureInfo.GetCultureInfo("pl-PL")))))
{
if (e.Modifiers == (Keys.Alt | Keys.Control) ||
(e.Modifiers == (Keys.RMenu)) //right alt key as well
)
{
switch (e.KeyCode)
{
case Keys.Z: // "ż"
case Keys.X: // "ź"
e.Handled = true;
break;
}
}
}


Enjoy!
External verification page for ISO 9000:2000 certificate
ISO 9001:2000
certified