Exemplo n.º 1
0
        internal static String GetVKText(int keyCode)
        {
            VKCollection vkCollect = VKCollection;
            Integer      key       = Convert.ToInt32(keyCode);
            String       name      = vkCollect.FindName(key);

            if (name != null)
            {
                return(name.Substring(3));
            }
            int expected_modifiers = (Modifier.PUBLIC | Modifier.STATIC | Modifier.FINAL);

            Field[] fields = typeof(KeyEvent).DeclaredFields;
            for (int i = 0; i < fields.Length; i++)
            {
                try
                {
                    if (fields[i].Modifiers == expected_modifiers && fields[i].Type == Integer.TYPE && fields[i].Name.StartsWith("VK_", StringComparison.Ordinal) && fields[i].getInt(typeof(KeyEvent)) == keyCode)
                    {
                        name = fields[i].Name;
                        vkCollect.Put(name, key);
                        return(name.Substring(3));
                    }
                }
                catch (IllegalAccessException)
                {
                    assert(false);
                }
            }
            return("UNKNOWN");
        }
Exemplo n.º 2
0
        /// <summary>
        /// Returns the integer constant for the KeyEvent.VK field named
        /// <code>key</code>. This will throw an
        /// <code>IllegalArgumentException</code> if <code>key</code> is
        /// not a valid constant.
        /// </summary>
        private static int GetVKValue(String key)
        {
            VKCollection vkCollect = VKCollection;

            Integer value = vkCollect.FindCode(key);

            if (value == null)
            {
                int          keyCode = 0;
                const String errmsg  = "String formatted incorrectly";

                try
                {
                    keyCode = typeof(KeyEvent).GetField(key).getInt(typeof(KeyEvent));
                }
                catch (NoSuchFieldException)
                {
                    throw new IllegalArgumentException(errmsg);
                }
                catch (IllegalAccessException)
                {
                    throw new IllegalArgumentException(errmsg);
                }
                value = Convert.ToInt32(keyCode);
                vkCollect.Put(key, value);
            }
            return(value.IntValue());
        }