예제 #1
0
        /// <summary>
        /// Adds a key modification data to the collection of the key modifications of the active device.
        /// </summary>
        /// <param name="modifyData">Structure that contains the key modification data to be added.</param>
        public void KeyboardAddKeyModifying(KeyModifyData modifyData)
        {
            var currentModifications = KeyboardGetKeyModifying();

            if (currentModifications.ModifyCount == 0)
            {
                currentModifications.ModifyCount = 1;
                currentModifications.ModifyData  = new KeyModifyData[1] {
                    modifyData
                };
                KeyboardSetModification(currentModifications);
                return;
            }
            for (int i = 0; i < currentModifications.ModifyData.Length; i++)
            {
                if (currentModifications.ModifyData[i].KeyStatePredicates == modifyData.KeyStatePredicates &&
                    currentModifications.ModifyData[i].FromScanCode == modifyData.FromScanCode &&
                    currentModifications.ModifyData[i].ToScanCode == modifyData.ToScanCode)
                {
                    return;//already exists
                }
            }

            Array.Resize(ref currentModifications.ModifyData, currentModifications.ModifyData.Length + 1);
            currentModifications.ModifyData[currentModifications.ModifyData.Length - 1] = modifyData;
            currentModifications.ModifyCount = (ushort)currentModifications.ModifyData.Length;

            KeyboardSetModification(currentModifications);
        }
예제 #2
0
        /// <summary>
        /// Removes a key modifying data from the collection of key modifications of the active device.
        /// </summary>
        /// <param name="modifyData">Structure that contains the key modification data to be removed.</param>
        public void KeyboardRemoveKeyModifying(KeyModifyData modifyData)
        {
            var currentModifications = KeyboardGetKeyModifying();

            if (currentModifications.ModifyCount == 0 || currentModifications.ModifyData == null)
            {
                return;
            }

            currentModifications.ModifyData = currentModifications.ModifyData.Where(d => d.KeyStatePredicates != modifyData.KeyStatePredicates ||
                                                                                    d.FromScanCode != modifyData.FromScanCode ||
                                                                                    d.ToScanCode != modifyData.ToScanCode).ToArray();

            KeyboardSetModification(currentModifications);
        }