Beispiel #1
0
        /// <summary>
        /// Adds a key filtering data to the collection of key filters of the active device.
        /// If the key filtering mode of the active device is not currently set to
        ///	'KEY_FLAG_SCANCODE', it will be set to this mode.
        /// </summary>
        /// <param name="filterData">Structure that contains the key filtering data to be added.</param>
        public void KeyboardAddKeyFiltering(KeyFilterData filterData)
        {
            var currentFiltering = KeyboardGetKeyFiltering();

            if (currentFiltering.FlagOrCount == 0 || currentFiltering.FilterMode != FilterMode.KEY_FLAG_AND_SCANCODE)
            {
                currentFiltering.FilterMode  = FilterMode.KEY_FLAG_AND_SCANCODE;
                currentFiltering.FlagOrCount = 1;
                currentFiltering.FilterData  = new KeyFilterData[1] {
                    filterData
                };
                KeyboardSetFiltering(currentFiltering);
                return;
            }
            for (int i = 0; i < currentFiltering.FilterData.Length; i++)
            {
                if (currentFiltering.FilterData[i].KeyFlagPredicates == filterData.KeyFlagPredicates &&
                    currentFiltering.FilterData[i].ScanCode == filterData.ScanCode)
                {
                    return;//already exists
                }
            }

            Array.Resize(ref currentFiltering.FilterData, currentFiltering.FilterData.Length + 1);
            currentFiltering.FilterData[currentFiltering.FilterData.Length - 1] = filterData;
            currentFiltering.FlagOrCount = (ushort)currentFiltering.FilterData.Length;
            KeyboardSetFiltering(currentFiltering);
        }
Beispiel #2
0
        /// <summary>
        /// Removes a key filtering data from the collection of key filters of the active device.
        /// </summary>
        /// <param name="filterData">Filter data to be removed.</param>
        public void KeyboardRemoveKeyFiltering(KeyFilterData filterData)
        {
            var currentFiltering = KeyboardGetKeyFiltering();

            if (currentFiltering.FlagOrCount == 0 || currentFiltering.FilterData == null || currentFiltering.FilterMode != FilterMode.KEY_FLAG_AND_SCANCODE)
            {
                return;
            }
            currentFiltering.FilterData = currentFiltering.FilterData.Where(d => d.KeyFlagPredicates != filterData.KeyFlagPredicates ||
                                                                            d.ScanCode != filterData.ScanCode).ToArray();

            if (currentFiltering.FilterData.Length == 0)
            {
                currentFiltering.FilterMode = FilterMode.KEY_NONE;
            }
            KeyboardSetFiltering(currentFiltering);
        }