The following works for the official portugues keyboard... Have fun...
public class Portuguese_Keyboard : TextBoxKeyboard
{
#region Windows - Latin char table
private struct KeyToChar
{
public Byte Code;
public Char Char;
}
private KeyToChar[] Default = new KeyToChar[]
{
new KeyToChar() { Code = 220, Char='\\'},
new KeyToChar() { Code = 219, Char='\''},
new KeyToChar() { Code = 221, Char='«'},
new KeyToChar() { Code = 187, Char='´'},
new KeyToChar() { Code = 191, Char='~'},
new KeyToChar() { Code = 186, Char='+'},
new KeyToChar() { Code = 222, Char='º'},
new KeyToChar() { Code = 192, Char='ç'},
new KeyToChar() { Code = 189, Char='-'},
new KeyToChar() { Code = 190, Char='.'},
new KeyToChar() { Code = 188, Char=','},
new KeyToChar() { Code = 226, Char='<'},
new KeyToChar() { Code = 106, Char='*'},
new KeyToChar() { Code = 111, Char='/'},
new KeyToChar() { Code = 109, Char='-'},
new KeyToChar() { Code = 107, Char='+'},
};
private KeyToChar[] Shifted = new KeyToChar[]
{
new KeyToChar() { Code = 220, Char='|'},
new KeyToChar() { Code = 219, Char='?'},
new KeyToChar() { Code = 221, Char='»'},
new KeyToChar() { Code = 187, Char='`'},
new KeyToChar() { Code = 191, Char='^'},
new KeyToChar() { Code = 186, Char='*'},
new KeyToChar() { Code = 222, Char='ª'},
new KeyToChar() { Code = 192, Char='Ç'},
new KeyToChar() { Code = 189, Char='_'},
new KeyToChar() { Code = 190, Char=':'},
new KeyToChar() { Code = 188, Char=';'},
new KeyToChar() { Code = 226, Char='>'},
new KeyToChar() { Code = 48, Char='='},
new KeyToChar() { Code = 49, Char='!'},
new KeyToChar() { Code = 50, Char='"'},
new KeyToChar() { Code = 51, Char='#'},
new KeyToChar() { Code = 52, Char='$'},
new KeyToChar() { Code = 53, Char='%'},
new KeyToChar() { Code = 54, Char='&'},
new KeyToChar() { Code = 55, Char='/'},
new KeyToChar() { Code = 56, Char='('},
new KeyToChar() { Code = 57, Char=')'},
};
private KeyToChar[] Alted = new KeyToChar[]
{
new KeyToChar() { Code = 50, Char='@'},
new KeyToChar() { Code = 51, Char='£'},
new KeyToChar() { Code = 52, Char='§'},
new KeyToChar() { Code = 55, Char='{'},
new KeyToChar() { Code = 56, Char='['},
new KeyToChar() { Code = 57, Char=']'},
new KeyToChar() { Code = 48, Char='}'},
new KeyToChar() { Code = 187, Char=']'},
new KeyToChar() { Code = 69, Char='€'},
new KeyToChar() { Code = 186, Char='¨'},
};
#endregion
private Boolean m_IsLeftAct = false;
private Boolean m_IsRightAct = false;
private Boolean m_IsTopAct = false;
private Boolean m_IsPointed = false;
private Boolean m_IsTilde = false;
public override event KeyEventHandler OnUnknown;
public override String Description { get { return "Portuguese"; } }
public override TextBoxKeyboard CreateInstance()
{
return new Portuguese_Keyboard();
}
public override String HandleKeyDown(Object InSender, KeyEventArgs InArgs)
{
// detect and dispatch generic control codes...
if (base.HandleKeyDown(InSender, InArgs) == null)
return "";
// if only Ctrl is down, no char will be displayed...
if (IsCtrlDown && !IsAltDown)
return "";
// handle possible text codes...
Int32 Code = InArgs.PlatformKeyCode;
String c = null;
if (((Code >= 48) && (Code <= 58)) || ((Code >= 65) && (Code <= 90)) || (Code == 32))
c = Convert.ToChar((Byte)Code).ToString().ToLower();
if (IsAltDown && IsCtrlDown) // "Alt Gr" key...
{
for (int i = 0; i < Alted.Length; i++)
{
if (Alted[ i ].Code == (Int32)Code)
{
c = Alted[ i ].Char.ToString();
break;
}
}
}
else if (IsShiftDown)
{
for (int i = 0; i < Shifted.Length; i++)
{
if (Shifted[ i ].Code == (Int32)Code)
{
c = Shifted[ i ].Char.ToString();
break;
}
}
if (c != null)
c = c.ToUpper();
}
else
{
for (int i = 0; i < Default.Length; i++)
{
if (Default[ i ].Code == (Int32)Code)
{
c = Default[ i ].Char.ToString();
break;
}
}
}
// check for unrecognized characters...
if (c == null)
{
if (OnUnknown != null)
OnUnknown(InSender, InArgs);
return "";
}
if (m_IsRightAct)
{
m_IsRightAct = false;
if (c.Length > 0)
{
switch (c[0])
{
case ' ': c = "´"; break;
case 'e': c = "é"; break;
case 'a': c = "á"; break;
case 'i': c = "í"; break;
case 'o': c = "ó"; break;
case 'u': c = "ú"; break;
case 'E': c = "É"; break;
case 'A': c = "Á"; break;
case 'I': c = "Í"; break;
case 'O': c = "Ó"; break;
case 'U': c = "Ú"; break;
default: c = "´" + c; break;
}
}
}
else if (m_IsLeftAct)
{
m_IsLeftAct = false;
if (c.Length > 0)
{
switch (c[0])
{
case ' ': c = "`"; break;
case 'e': c = "è"; break;
case 'a': c = "à"; break;
case 'i': c = "ì"; break;
case 'o': c = "ò"; break;
case 'u': c = "ù"; break;
case 'E': c = "È"; break;
case 'A': c = "À"; break;
case 'I': c = "Ì"; break;
case 'O': c = "Ò"; break;
case 'U': c = "Ù"; break;
default: c = "`" + c; break;
}
}
}
else if (m_IsTopAct)
{
m_IsTopAct = false;
if (c.Length > 0)
{
switch (c[0])
{
case ' ': c = "^"; break;
case 'e': c = "ê"; break;
case 'a': c = "â"; break;
case 'i': c = "î"; break;
case 'o': c = "ô"; break;
case 'u': c = "û"; break;
case 'E': c = "Ê"; break;
case 'A': c = "Â"; break;
case 'I': c = "Î"; break;
case 'O': c = "Ô"; break;
case 'U': c = "Û"; break;
default: c = "^" + c; break;
}
}
}
else if (m_IsTilde)
{
m_IsTilde = false;
if (c.Length > 0)
{
switch (c[0])
{
case ' ': c = "~"; break;
case 'a': c = "ã"; break;
case 'n': c = "ñ"; break;
case 'o': c = "õ"; break;
case 'A': c = "Ã"; break;
case 'N': c = "Ñ"; break;
case 'O': c = "Õ"; break;
default: c = "~" + c; break;
}
}
}
else if (m_IsPointed)
{
m_IsPointed = false;
if (c.Length > 0)
{
switch (c[0])
{
case ' ': c = "¨"; break;
case 'e': c = "ë"; break;
case 'a': c = "ä"; break;
case 'i': c = "ï"; break;
case 'o': c = "ö"; break;
case 'u': c = "ü"; break;
case 'E': c = "Ë"; break;
case 'A': c = "Ä"; break;
case 'I': c = "Ï"; break;
case 'O': c = "Ö"; break;
case 'U': c = "Ü"; break;
default: c = "¨" + c; break;
}
}
}
else
{
if (c == "´")
{
if (!m_IsRightAct)
c = "";
m_IsRightAct = true;
}
if (c == "^")
{
if (!m_IsTopAct)
c = "";
m_IsTopAct = true;
}
if (c == "`")
{
if (!m_IsLeftAct)
c = "";
m_IsLeftAct = true;
}
if (c == "~")
{
if (!m_IsTilde)
c = "";
m_IsTilde = true;
}
if (c == "¨")
{
if (!m_IsPointed)
c = "";
m_IsPointed = true;
}
}
return c;
}
}
regards, christoph husse
(if this has answered your question please mark as answered ;-)