Exemplo n.º 1
0
        public override string GetCodeStr(IKeyGetter keyGetter)
        {
            string result = string.Empty;

            for (int column = 0; column < Hardware.Keyboard.NumColumns; column++)
            {
                byte thisValue = 0;
                for (int row = 0; row < Hardware.Keyboard.NumRows; row++)
                {
                    if (Hardware.Keyboard.IsValidKey(column, row))
                    {
                        KeyBase xkey = keyGetter.GetKey(column, row);
                        if (!xkey.IsDown)
                        {
                            continue;
                        }

                        KeyBase singleXkey = keyGetter.GetSingleKey(column, row);
                        if (singleXkey != null)
                        {
                            thisValue += singleXkey.GetRowDataValue();
                        }
                    }
                }
                result += thisValue + ".";
            }
            return(result.TrimEnd('.'));
        }
        void Data_DataChanged(object sender, EventArgs e)
        {
            List <KeyBase> keysDown = new List <KeyBase>();

            for (int column = 0; column < Hardware.Keyboard.NumColumns; column++)
            {
                byte blockedKeyMask = XkeysRaw.Data.BlockedKeysMask[column];
                byte keyCode        = (byte)(XkeysRaw.Data.LastKeyCode[column] & (255 - blockedKeyMask));

                if (keyCode == 0)
                {
                    continue;
                }

                for (int row = 0; row < Hardware.Keyboard.NumRows; row++)
                {
                    if ((keyCode & (byte)Math.Pow(2, row)) != 0)
                    {
                        KeyBase key = xkeyLayout.GetKey(column, row);
                        if (!keysDown.Contains(key))
                        {
                            keysDown.Add(key);
                        }
                    }
                }
            }
            OnXkeyPressed(keysDown, xkeyLayout.GetCodeStr());

            /*
             * 3. Set a timer for about 500ms and when it fires check the data again to make sure the key isn't "stuck".
             */
        }
Exemplo n.º 3
0
        public override List <KeyBase> GetPressedKeys(string customData, IKeyGetter keyGetter)
        {
            List <KeyBase> keysPressed = new List <KeyBase>();

            string[] columns = customData.Split('.');
            for (int column = 0; column < columns.Length; column++)
            {
                int value;
                if (int.TryParse(columns[column], out value))
                {
                    if (value == 0)
                    {
                        continue;
                    }
                    for (int row = 0; row < Hardware.Keyboard.NumRows; row++)
                    {
                        byte rowMask = (byte)(Math.Pow(2, row));
                        if ((rowMask & value) == rowMask)
                        {
                            KeyBase keyPressed = keyGetter.GetKey(column, row);
                            if (keysPressed.Contains(keyPressed))
                            {
                                continue;
                            }
                            keysPressed.Add(keyPressed);
                        }
                    }
                }
            }
            return(keysPressed);
        }
Exemplo n.º 4
0
        public bool CanBeSquare()
        {
            if (Count != 4)
            {
                return(false);
            }

            // Four keys selected....

            if (GetGroupType() != KeyGroupType.NoGroup)
            {
                return(false);
            }

            // All four keys can be grouped...

            KeyBase[] keys = new KeyBase[4];
            keys[0] = selectedKeys[0];
            keys[1] = selectedKeys[1];
            keys[2] = selectedKeys[2];
            keys[3] = selectedKeys[3];

            KeyBase topLeftKey = GetTopLeftKey(keys);

            if (topLeftKey == null)
            {
                return(false);
            }

            // OK, we have the top left key. Now let's see if the other three keys are in the positions we're expecting...

            if (!(HasKeyAt(keys, topLeftKey.Column + 1, topLeftKey.Row) && HasKeyAt(keys, topLeftKey.Column, topLeftKey.Row + 1) && HasKeyAt(keys, topLeftKey.Column + 1, topLeftKey.Row + 1)))
            {
                return(false);
            }

            // OK, we now know the four keys are adjacent. Finally, let's make sure the four keys are in a legal position on the x-keys...

            if (topLeftKey.Row == 1 || topLeftKey.Row > 5)
            {
                return(false);
            }

            if (topLeftKey.Row == 0 && topLeftKey.Column > 7)
            {
                return(false);
            }

            if (topLeftKey.Row > 1)
            {
                if (topLeftKey.Column == 1 || topLeftKey.Column == 5 || topLeftKey.Column > 6)
                {
                    return(false);
                }
            }

            return(true);
        }
Exemplo n.º 5
0
        public bool CanBeWide()
        {
            if (Count != 2)
            {
                return(false);
            }

            // Two keys selected....

            if (GetGroupType() != KeyGroupType.NoGroup)
            {
                return(false);
            }

            // Both keys can be grouped...

            KeyBase key1 = selectedKeys[0];
            KeyBase key2 = selectedKeys[1];

            if (key1.Row != key2.Row)
            {
                return(false);
            }

            // Same row...

            int row = key1.Row;

            if (Math.Abs(key1.Column - key2.Column) != 1)
            {
                return(false);
            }

            // Adjacent columns...

            int leftColumn = Math.Min(key1.Column, key2.Column);

            if (row <= 1)           // top two rows have 9 keys...
            {
                if (leftColumn > 7) // Wide keys cannot start on or after column 7 (zero indexed).
                {
                    return(false);
                }
            }
            else // bottom section
            {
                if (leftColumn == 1 || leftColumn == 5 || leftColumn > 6) // Wide keys in the bottom section cannot start on column 1, 5, 7 or greater (zero indexed).
                {
                    return(false);
                }
            }

            return(true);
        }
Exemplo n.º 6
0
        public override void Load(DecoupledStorage storage, string section, int index)
        {
            base.Load(storage, section, index);
            Type = (KeyGroupType)storage.ReadEnum <KeyGroupType>(section, "Type" + index, KeyGroupType.Wide);

            int numElements = storage.ReadInt32(section, "GroupCount" + index, 0);

            for (int i = 0; i < numElements; i++)
            {
                keys.Add(KeyBase.CreateAndLoad(storage, String.Format("{0}.Group{1}", section, index), i));
            }
        }
Exemplo n.º 7
0
        public void Load()
        {
            Keys.Clear();
            DecoupledStorage storage = OptXkeysLayout.Storage;
            int numKeys = storage.ReadInt32("Layout", "Count");

            for (int i = 0; i < numKeys; i++)
            {
                Keys.Add(KeyBase.CreateAndLoad(storage, "Layout", i));
            }
            BlockSettingsChanged();
        }
Exemplo n.º 8
0
        public string GetKeyName(int column, int row)
        {
            KeyBase key = GetKey(column, row);

            if (key != null)
            {
                return(key.Name);
            }
            else
            {
                return(null);
            }
        }
Exemplo n.º 9
0
        public static KeyBase CreateAndLoad(DecoupledStorage storage, string section, int index)
        {
            KeyBase key = null;

            if (storage.ReadBoolean(section, "IsGroup" + index, false))
            {
                key = new KeyGroup();
            }
            else
            {
                key = new Key();
            }
            key.Load(storage, section, index);
            return(key);
        }
Exemplo n.º 10
0
        KeyBase GetTopLeftKey(KeyBase[] keys)
        {
            int topKeyIndex  = GetTopKeyIndex(keys);
            int leftKeyIndex = GetLeftKeyIndex(keys);

            KeyBase topLeftKey = null;

            int leftColumn = keys[leftKeyIndex].Column;
            int topRow     = keys[topKeyIndex].Row;

            for (int i = 0; i < keys.Length; i++)
            {
                if (keys[i].IsAt(leftColumn, topRow))
                {
                    topLeftKey = keys[i];
                }
            }
            return(topLeftKey);
        }
Exemplo n.º 11
0
        public bool CanBeTall()
        {
            if (Count != 2)
            {
                return(false);
            }

            // Two keys selected....

            if (GetGroupType() != KeyGroupType.NoGroup)
            {
                return(false);
            }

            // Both keys can be grouped...

            KeyBase key1 = selectedKeys[0];
            KeyBase key2 = selectedKeys[1];

            if (key1.Column != key2.Column)
            {
                return(false);
            }

            // Same column...

            if (Math.Abs(key1.Row - key2.Row) != 1)
            {
                return(false);
            }

            // Adjacent rows...

            int topRow = Math.Min(key1.Row, key2.Row);

            if (topRow == 1 || topRow > 5) // Tall keys cannot start on row 1 (zero indexed) or on or after row 6.
            {
                return(false);
            }

            return(true);
        }
Exemplo n.º 12
0
        /// <summary>
        /// Gets the single key at the specified column and row. If a group key
        /// (tall, wide, or square) is at the specified location, then that group
        /// is drilled into to find and return the actual subkey at the column and
        /// row.
        /// </summary>
        public KeyBase GetSingleKey(int column, int row)
        {
            KeyBase  key      = GetKey(column, row);
            KeyGroup keyGroup = key as KeyGroup;

            if (keyGroup == null)
            {
                return(key);
            }

            foreach (KeyBase subkey in keyGroup.Keys)
            {
                if (subkey.IsAt(column, row))
                {
                    return(subkey);
                }
            }

            return(null);
        }
        private void pnlKeyPreview_MouseMove(object sender, MouseEventArgs e)
        {
            // TODO: Fix this so tool tips over the layout keys actually work.
            int row;
            int column;

            if (xkeysPainter.IsHit(e.X, e.Y, out column, out row))
            {
                KeyBase key = xkeyLayout.GetKey(column, row);
                if (key != lastHoverKey)
                {
                    lastHoverKey = key;
                    if (key != null)
                    {
                        toolTip1.SetToolTip(pnlKeyPreview, key.Name);
                    }
                }
            }
            else
            {
                toolTip1.SetToolTip(pnlKeyPreview, null);
            }
        }
Exemplo n.º 14
0
 public void Remove(KeyBase key)
 {
     keys.Remove(key);
 }
Exemplo n.º 15
0
 public void AddKeyToSelection(KeyBase key)
 {
     selectedKeys.Add(key);
 }
Exemplo n.º 16
0
 public void AddKey(KeyBase key)
 {
     selectedKeys.Add(key);
 }