Esempio n. 1
0
        public static int[] GetRowTerminators(KeyboardLayoutType layout)
        {
            // First five rows are the hashes of the terminator keys
            // (Backspace, Enter, R Shift, R Ctrl for Euro layout)

            switch (layout)
            {
            default:     // includes case KeyboardLayoutType.US:
                return(new [] {
                    KeyHasher.GetHashFromKeyData(14, 0),
                    KeyHasher.GetHashFromKeyData(43, 0),
                    KeyHasher.GetHashFromKeyData(28, 0),
                    KeyHasher.GetHashFromKeyData(54, 224),
                    KeyHasher.GetHashFromKeyData(29, 224)
                });

            case KeyboardLayoutType.Punjabi:
            case KeyboardLayoutType.European:

                return(new [] {
                    KeyHasher.GetHashFromKeyData(14, 0),
                    KeyHasher.GetHashFromKeyData(28, 0),
                    99999,
                    KeyHasher.GetHashFromKeyData(54, 224),
                    KeyHasher.GetHashFromKeyData(29, 224)
                });
            }
        }
Esempio n. 2
0
        private static Bitmap WriteCaption(Bitmap bmp, int scancode, int extended, Color fontColour)
        {
            string caption = AppController.GetKeyName(scancode, extended) ?? String.Format("SC: {0} EX: {1}", scancode, extended);

            // Blank keys.
            if (String.IsNullOrEmpty(caption))
            {
                return(bmp);
            }

            bool overlong    = false;
            bool localizable = false;

            int hash = KeyHasher.GetHashFromKeyData(scancode, extended);

            if (AppController.IsOverlongKey(hash))
            {
                overlong = true;
            }

            if (AppController.IsLocalizableKey(hash))
            {
                localizable = true;
            }

            return(WriteCaption(bmp, caption, overlong, localizable, fontColour));
        }
Esempio n. 3
0
        public Dictionary <string, int> GetGroupMembers(string groupname, int threshold)
        {
            // Enumerate group.
            string queryExpression;

            if (groupname == AllKeysGroupName)
            {
                queryExpression = @"/KeycodeData/keycodes[group!='Unmappable Keys']";
            }
            else if (groupname == _commonlyUsedKeysGroupName)
            {
                queryExpression = @"/KeycodeData/keycodes[useful>='2'" + "]";
            }
            else
            {
                queryExpression = @"/KeycodeData/keycodes[group='" + groupname + "' and useful>='" + threshold.ToString(System.Globalization.CultureInfo.InvariantCulture.NumberFormat) + "']";
            }

            XPathNodeIterator iterator;

            iterator = (XPathNodeIterator)_navigator.Select(queryExpression);

            // Gives us a bunch of keycode nodes.
            // Given the scancode / extended from each node, ask for the name from the current layout.
            int scancode, extended;

            Dictionary <string, int> dir = new Dictionary <string, int>(iterator.Count);

            foreach (XPathNavigator node in iterator)
            {
                scancode = Int32.Parse(GetElementValue("sc", node), CultureInfo.InvariantCulture.NumberFormat);
                extended = Int32.Parse(GetElementValue("ex", node), CultureInfo.InvariantCulture.NumberFormat);
                string name = AppController.GetKeyName(scancode, extended);
                if (dir.ContainsKey(name)) // ArgumentException results when trying to add duplicate key..
                {
                    Console.WriteLine("Duplicate name error: Name {0} Existing Scancode : {1} Scancode: {2}", name, dir[name], scancode);
                }
                else
                {
                    dir.Add(name, KeyHasher.GetHashFromKeyData(scancode, extended));
                }
            }

            return(dir);
        }
Esempio n. 4
0
        private List <int> GetKeys(bool localizable)
        {
            string expression = @"/KeycodeData/keycodes[localize = '" + (localizable ? "true" : "false") + "']";

            XPathNodeIterator iterator = (XPathNodeIterator)_navigator.Select(expression);

            List <int> keys = new List <int>(iterator.Count);

            for (int i = 0; i < iterator.Count; i++)
            {
                iterator.MoveNext();
                int scancode = Int32.Parse(GetElementValue("sc", iterator.Current), CultureInfo.InvariantCulture.NumberFormat);
                int extended = Int32.Parse(GetElementValue("ex", iterator.Current), CultureInfo.InvariantCulture.NumberFormat);
                keys.Add(KeyHasher.GetHashFromKeyData(scancode, extended));
            }

            return(keys);
        }
Esempio n. 5
0
        public string GetKeyNameFromCode(int code)
        {
            int scancode = KeyHasher.GetScancodeFromHash(code);
            int extended = KeyHasher.GetExtendedFromHash(code);

            string expression = @"/KeycodeData/keycodes[sc = '" + scancode.ToString(CultureInfo.InvariantCulture.NumberFormat) + "' and ex = '" + extended.ToString(CultureInfo.InvariantCulture.NumberFormat) + "'] ";

            XPathNodeIterator iterator = (XPathNodeIterator)_navigator.Select(expression);

            string name = String.Empty;

            if (iterator.Count == 1)
            {
                iterator.MoveNext();
                name = GetElementValue("name", iterator.Current);
            }

            return(name);
        }
Esempio n. 6
0
        public static string GetKeyName(int scancode, int extended)
        {
            // Look up the values in the current localized layout.
            if (scancode == 0 && extended == 0)
            {
                return("Disabled");
            }

            if (scancode == -1 && extended == -1)
            {
                return("");
            }

            int hash = KeyHasher.GetHashFromKeyData(scancode, extended);

            if (_currentLayout.ContainsKey(hash))
            {
                return(_currentLayout.GetKeyName(hash));
            }

            Console.WriteLine("Unknown key: sc {0} ex {1}", scancode, extended);
            return("Unknown");
        }
Esempio n. 7
0
        private void GetLocalizableKeyNames()
        {
            _localizableKeyNames.Clear();

            foreach (int hash in _localizableKeys)
            {
                // None of the localizable names need the extended bit.
                int scancode = KeyHasher.GetScancodeFromHash(hash);

                // Need to track if a localizable key is a symbol - shifter-symbol
                // combination but it's length is not 3 - i.e. instead of 1 and !
                // it is Qaf and RehYehAlefLam (as on the Farsi keyboard)

                bool   overlong = false;
                string name     = KeyboardHelper.GetKeyName(scancode, ref overlong);

                _nonLocalizableKeyNames.Add(hash, name);
                if (overlong)
                {
                    // Console.WriteLine("Adding overlong key: code {0} name length: {1} name: {2}", hash, name.Length, name);
                    _overlongkeys.Add(hash);
                }
            }
        }
Esempio n. 8
0
 public override int GetHashCode()
 {
     return(KeyHasher.GetHashFromKey(From) * 31 + KeyHasher.GetHashFromKey(To));
 }
Esempio n. 9
0
 // override object.GetHashCode
 public override int GetHashCode()
 {
     return(KeyHasher.GetHashFromKeyData(Scancode, Extended));
 }