Ejemplo n.º 1
0
            public bool IsPressed(InputStack input)
            {
                foreach (InputStack inputStack in Stacks)
                {
                    //if (inputStack.Inputs.Count == input.Inputs.Count)
                    {
                        bool anyNegative = false;
                        foreach (var inputItem in inputStack.Inputs)
                        {
                            if (!input.Inputs.Any(x =>
                                                  x.PressType == inputItem.PressType &&
                                                  x.GetType() == inputItem.GetType() &&
                                                  (
                                                      (x.GetType() == typeof(GamepadControl) && ((GamepadControl)x).Button == ((GamepadControl)inputItem).Button) ||
                                                      (x.GetType() == typeof(MouseControl) && ((MouseControl)x).MouseButton == ((MouseControl)inputItem).MouseButton) ||
                                                      (x.GetType() == typeof(KeyboardControl) && ((KeyboardControl)x).Key == ((KeyboardControl)inputItem).Key)
                                                  )))
                            {
                                anyNegative = true;
                                break;
                            }
                        }

                        if (!anyNegative)
                        {
                            return(true);
                        }
                    }
                }

                return(false);
            }
Ejemplo n.º 2
0
        public void ReturnGroup(string text, string value)
        {
            var stack   = new InputStack(text);
            var command = new PhraseToken(text, value);
            var result  = command.Process(stack);

            Assert.NotNull(result);
            Assert.Equal(value, result.Value);
        }
Ejemplo n.º 3
0
        public void ReturnNumberWithDigitInput(string text, int expectedResultValue)
        {
            NumberToken command = new NumberToken();
            var         stack   = new InputStack(text);
            var         result  = command.Process(stack);

            Assert.NotNull(result);
            Assert.Equal(expectedResultValue, result.Value);
            Assert.Equal(0, result.Score);
        }
Ejemplo n.º 4
0
        public void ReturnGroup(string text, decimal groupNumber)
        {
            IEosService eosService = GetMockService();
            var         stack      = new InputStack(text);

            var command = new GroupToken(eosService);
            var result  = command.Process(stack);

            Assert.NotNull(result);
            Assert.Equal(groupNumber, result.Value);
        }
Ejemplo n.º 5
0
    public void Initialize(ConversationMedium conversationMedium)
    {
        conversation = conversationMedium;
        KnownActors  = conversation.GetActorNames();

        KnownActors.Add(Me);
        inputStack = Instantiate(inputStackObject, transform).GetComponent <InputStack>();
        inputStack.Initialize(this, conversationMedium.GetTopics(Me), conversationMedium.GetThoughts(Me));
        outputStack = Instantiate(outputStackObject, transform).GetComponent <OutputStack>();
        outputStack.Initialize(this);
    }
Ejemplo n.º 6
0
        protected override MutableObject Mutate(MutableObject mutable)
        {
            foreach (var entry in AxisKey.GetEntries(mutable))
            {
                TargetField.SetValue(OutputStack.TransformValue(
                                         ConversionFunc(
                                             InputStack.TransformValue(AxisKey.GetValue(entry)), entry)),
                                     entry);
            }

            return(mutable);
        }
Ejemplo n.º 7
0
        protected override MutableObject Mutate(MutableObject mutable)
        {
            foreach (var entry in AxisKey.GetEntries(mutable))
            {
                TargetField.SetValue(OutputStack.TransformValue(
                                         string.Compare(InputStack.TransformValue(AxisKey.GetValue(entry)),
                                                        InputStack.TransformValue(ToMatch.GetValue(entry)),
                                                        StringComparison.InvariantCultureIgnoreCase) == 0),
                                     entry);
            }

            return(mutable);
        }
Ejemplo n.º 8
0
        protected override MutableObject Mutate(MutableObject mutable)
        {
            var entries = AxisKey.GetEntries(mutable);

            var foundStrings = new HashSet <T>();

            // identify the set of unique keys
            foreach (var entry in entries)
            {
                var axisKey = InputStack.TransformValue(AxisKey.GetValue(entry));

                if (!foundStrings.Contains(axisKey))
                {
                    foundStrings.Add(axisKey);
                }
            }

            // DO NOT sort the keys
            //var sortedKeys = foundStrings.ToList();
            //sortedKeys.Sort();

            // index the values
            var axisValues = GroupId.GetFirstValue(mutable) == "" ?
                             new Dictionary <T, int>()
                : DataShare.ContainsKey(GroupId.GetFirstValue(mutable)) ?
                             DataShare[GroupId.GetFirstValue(mutable)]
                : new Dictionary <T, int>();

            int i = 0;

            foreach (var key in foundStrings) //sortedKeys
            {
                axisValues[key] = OutputStack.TransformValue(i++);
            }

            // finally, write the new axis value into each entry
            entries = AxisKey.GetEntries(mutable);
            foreach (var entry in entries)
            {
                IndexAxis.SetValue(
                    axisValues[InputStack.TransformValue(AxisKey.GetValue(entry))],
                    entry);
            }

            if (GroupId.GetFirstValue(mutable) != "")
            {
                DataShare[GroupId.GetFirstValue(mutable)] = axisValues;
            }

            return(mutable);
        }
Ejemplo n.º 9
0
        /// <summary>
        /// Closes the current input object, indicating that its transformation has been completed.
        /// </summary>
        protected virtual void Close(object inputItem)
        {
            if (InputStack.Count == 0)
            {
                throw new InvalidOperationException("Cannot close: stack is already empty.");
            }
            TransformInfo ti = InputStack[InputStack.Count - 1];

            if (!object.ReferenceEquals(inputItem, ti.inputElement))
            {
                throw new InvalidOperationException("Cannot close: supplied object is not on top of the stack: " + inputItem + "," + ti.inputElement);
            }
            InputStack.RemoveAt(InputStack.Count - 1);
        }
Ejemplo n.º 10
0
    void Start()
    {
        InputStack.Push(this);

        debriefScreen.SetActive(false);
        deathScreen.SetActive(false);
        startScreen.SetActive(true);
        tutorialText.gameObject.SetActive(false);

        keyMgr = GetComponent <MultiKeyManager>();
        keyMgr.AddKey(KeyCode.W);
        keyMgr.AddKey(KeyCode.A);
        keyMgr.AddKey(KeyCode.S);
        keyMgr.AddKey(KeyCode.D);
    }
Ejemplo n.º 11
0
        public void ReturnMultipleResultsNumberWithDigitInput(string text, params int[] expectedResultValues)
        {
            NumberToken command = new NumberToken();
            var         stack   = new InputStack(text);

            Assert.Equal(expectedResultValues.Length, stack.Count);
            for (int i = 0; i < stack.Count; i++)
            {
                var result = command.Process(stack);

                stack.Pop();

                Assert.NotNull(result);
                Assert.Equal(expectedResultValues[i], result.Value);
                Assert.Equal(0, result.Score);
            }
        }
Ejemplo n.º 12
0
        public GroupMatchType IsMatch(InputStack command, int workingIndex = 0, string currentText = "")
        {
            currentText += command.ToList()[workingIndex];

            if (Label.Equals(currentText, StringComparison.OrdinalIgnoreCase))
            {
                //Check to see if the next token also matches, if not we have an exact match.
                if (IsMatch(command, workingIndex++, currentText) == GroupMatchType.None)
                {
                    return(GroupMatchType.Exact);
                }
            }
            if (Label.StartsWith(currentText))
            {
                return(IsMatch(command, workingIndex++, currentText));
            }

            return(GroupMatchType.None);
        }
Ejemplo n.º 13
0
    // ******************************

    private void BuildGame()
    {
        // Area
        _area = FindObjectOfType <Area>();

        // Async
        _async = gameObject.AddComponent <Async>();

        // Effects
        _effects = gameObject.AddComponent <Effects>();

        // Area Controller
        _areaController = gameObject.AddComponent <AreaController>();

        // UIController
        _uiController = gameObject.AddComponent <UIController>();

        // Gun Control
        _gunControl = gameObject.AddComponent <GunControl>();

        // Input
        _input = gameObject.AddComponent <InputStack>();
    }
Ejemplo n.º 14
0
    void InLevelUpdate()
    {
        if (!InputStack.IsActive(this))
        {
            return;
        }

        //----------------------------------------
        //  Reverse key
        //----------------------------------------
        if (Input.GetKeyDown(KeyCode.R))
        {
            if (activeWorm.Count == 1)
            {
                AudioSource.PlayClipAtPoint(error, transform.position);
            }
            else
            {
                // reverse head/tail
                activeWorm.GetFirst().isHead = false;
                activeWorm.Reverse();
                activeWorm.GetFirst().isHead = true;
                AudioSource.PlayClipAtPoint(reverse, transform.position);
            }
        }

        if (Input.GetKeyDown(KeyCode.Space))
        {
            if (activeWorm.Count == 1)
            {
                AudioSource.PlayClipAtPoint(error, transform.position);
            }
            else
            {
                // split in two!
                int        totalSegs = activeWorm.Count;
                int        numInNew  = totalSegs / 2;
                int        numInOld  = totalSegs - numInNew;
                List <Seg> newWorm   = new List <Seg>();
                for (int i = 0; i < numInNew; i++)
                {
                    newWorm.Add(activeWorm[numInOld + i]);
                    newWorm.GetLast().isHead   = false;
                    newWorm.GetLast().isActive = false;
                }
                worms.Add(newWorm);
                activeWorm.RemoveRange(numInOld, numInNew);
                AudioSource.PlayClipAtPoint(split, transform.position);

                // assign a key
                int key = GetFreeWormKey();

                if (key != -1)
                {
                    key2worm[key]     = newWorm;
                    worm2key[newWorm] = key;
                }
            }
        }

        for (int key = 1; key < 9; key++)
        {
            if (Input.GetKeyDown("" + key) && key2worm.ContainsKey(key))
            {
                // switch to this worm
                foreach (var seg in activeWorm)
                {
                    seg.isActive = false;
                    seg.isHead   = false;
                }

                activeWorm = key2worm[key];
                foreach (var seg in activeWorm)
                {
                    seg.isActive = true;
                    seg.isHead   = false;
                }
                activeWorm.GetFirst().isHead = true;
            }
        }

        repeatTimer -= Time.deltaTime;

        int dr = 0;
        int dc = 0;

        if (repeatTimer < 0)
        {
            KeyCode moveKey = keyMgr.GetActiveKey();

            if (moveKey == KeyCode.W)
            {
                dr -= 1;
            }
            else if (moveKey == KeyCode.S)
            {
                dr += 1;
            }
            else if (moveKey == KeyCode.A)
            {
                dc -= 1;
            }
            else if (moveKey == KeyCode.D)
            {
                dc += 1;
            }
        }

        if (dr != 0 || dc != 0)
        {
            var head  = activeWorm.GetFirst();
            var other = head.ent.Peek(dr, dc);

            if (other != null && other.GetComponent <LevelExit>() != null)
            {
                if (worms.Count > 1)
                {
                    AudioSource.PlayClipAtPoint(error, transform.position);
                    ThrobOutstandingItems();
                    Debug.Log("detached worms in level!");
                }
                // check for remaining fruits..
                else if (map.entsRoot.GetComponentsInChildren <Fruit>().Length > 0)
                {
                    AudioSource.PlayClipAtPoint(error, transform.position);
                    ThrobOutstandingItems();
                    Debug.Log("fruits remain!");
                }
                else
                {
                    AudioSource.PlayClipAtPoint(beatlevel, transform.position);

                    if (currLevel + 1 < levelOrder.Length)
                    {
                        SwitchLevel(currLevel + 1);
                    }
                    else
                    {
                        // beat!
                        map.Clear();
                        startScreen.SetActive(true);
                        state = "start";
                    }
                }
            }
            else if (other != null && other.GetComponent <Seg>() != null &&
                     !other.GetComponent <Seg>().isActive)
            {
                var hitBit = other.GetComponent <Seg>();
                if (RemergeTail(hitBit))
                {
                    AudioSource.PlayClipAtPoint(merge, transform.position);
                }
                else
                {
                    // hit a non-head or tail of the inactive worm. can't merge there.
                    AudioSource.PlayClipAtPoint(error, transform.position);
                }
            }
            else
            {
                // do move

                bool grew = false;
                // but maybe eating a fruit?
                if (other != null && other.GetComponent <Fruit>() != null)
                {
                    AudioSource.PlayClipAtPoint(grow, transform.position);

                    map.RemoveEntity(other);
                    Destroy(other.gameObject);

                    // create new worm segment at end later
                    grew = true;
                }

                Int2 endPos = activeWorm.GetLast().ent.pos;

                if (!TryMoveWorm(activeWorm, new Int2(dr, dc)))
                {
                    AudioSource.PlayClipAtPoint(bump, transform.position);
                }
                else
                {
                    if (grew)
                    {
                        var newSeg = map.SpawnPrefab(wormSegPrefab, endPos.row, endPos.col);
                        activeWorm.Add(newSeg.GetComponent <Seg>());
                    }
                    else
                    {
                        AudioSource.PlayClipAtPoint(move, transform.position);
                    }
                }
            }

            //----------------------------------------
            //  reset timer
            //  Do NOT do this if we did not move..
            //----------------------------------------
            if (repeatTimer < 0)
            {
                repeatTimer = repeatPeriod;
            }
        }
    }
Ejemplo n.º 15
0
    // Update is called once per frame
    void Update()
    {
        if (state == "start")
        {
            if (InputStack.IsActive(this) && Input.GetKeyDown(KeyCode.Space))
            {
                state = "level";
                startScreen.SetActive(false);
                SwitchLevel(0);
            }
        }
        else if (state == "level")
        {
            //----------------------------------------
            //  Handle player input
            //----------------------------------------
            InLevelUpdate();

            //----------------------------------------
            //  Cheats
            //----------------------------------------
            if (Input.GetKeyDown(KeyCode.Equals))
            {
                SwitchLevel(currLevel + 1);
            }
            if (Input.GetKeyDown(KeyCode.Minus))
            {
                SwitchLevel(currLevel - 1);
            }
            if (Input.GetKeyDown(KeyCode.Alpha0))
            {
                SwitchLevel(currLevel);
            }
        }
        else if (state == "dead")
        {
            if (InputStack.IsActive(this) && Input.GetKeyDown(KeyCode.Space))
            {
                deathScreen.SetActive(false);
                SwitchLevel(currLevel, false);
            }
        }
        else if (state == "debrief")
        {
            if (InputStack.IsActive(this) && Input.GetKeyDown(KeyCode.Space))
            {
                debriefScreen.SetActive(false);
                if (currLevel + 1 < levelOrder.Length)
                {
                    SwitchLevel(currLevel + 1);
                }
                else
                {
                    // beat game!
                    map.Clear();
                    startScreen.SetActive(true);
                    state = "start";
                }
            }
        }
        else if (state == "ending")
        {
        }
    }
Ejemplo n.º 16
0
 public void Initialize(InputStack outputStack)
 {
     myInput = outputStack;
 }
Ejemplo n.º 17
0
 void Awake()
 {
     inputstack = this;
     keyQueue   = new Queue();
     //GameObject.Find ("PlayCardArea").GetComponent<PlayArea> ();
 }
Ejemplo n.º 18
0
 /// <summary>
 /// Constructor for the <c>NodeReader</c> object. This is used
 /// to read XML events a input node objects from the event reader.
 /// </summary>
 /// <param name="reader">
 /// this is the event reader for the XML document
 /// </param>
 public NodeReader(EventReader reader) {
    this.stack = new InputStack();
    this.reader = reader;
 }
        }//method

        public void ResetSourceLocation(SourceLocation tokenStart, int position)
        {
            _currentInput = null;
            InputStack.Clear();
            _scanner.SetSourceLocation(tokenStart, position);
        }
Ejemplo n.º 20
0
        /// <summary>
        /// Opens the input object for transforming.
        /// </summary>
        /// <param name="inputItem">Input code element</param>
        protected virtual void Open(object inputItem)
        {
            TransformInfo ti = new TransformInfo(inputItem);

            InputStack.Add(ti);
        }
Ejemplo n.º 21
0
        //TODO Move ME
        //private void MidiInPort_MessageReceived(MidiInPort sender, MidiMessageReceivedEventArgs args)
        //{
        //    IMidiMessage receivedMidiMessage = args.Message;

        //    //System.Diagnostics.Debug.WriteLine(receivedMidiMessage.Timestamp.ToString());

        //    if (receivedMidiMessage.Type == MidiMessageType.NoteOn || receivedMidiMessage.Type == MidiMessageType.NoteOff)
        //    {
        //        int velocity = -1;
        //        byte note = receivedMidiMessage.Type == MidiMessageType.NoteOn ? ((MidiNoteOnMessage)receivedMidiMessage).Note : ((MidiNoteOffMessage)receivedMidiMessage).Note;
        //        if (receivedMidiMessage.Type == MidiMessageType.NoteOn)
        //        {
        //            velocity = ((MidiNoteOnMessage)receivedMidiMessage).Velocity;
        //        }
        //        MidiNote midiNote = new MidiNote(note, velocity);

        //        if (receivedMidiMessage.Type == MidiMessageType.NoteOn)
        //        {
        //            Solids.Mixer.NoteOn(midiNote);
        //        }

        //        if (receivedMidiMessage.Type == MidiMessageType.NoteOff)
        //        {
        //            Solids.Mixer.NoteOff(midiNote);
        //        }

        //        //  System.Diagnostics.Debug.WriteLine(((MidiNoteOnMessage)receivedMidiMessage).Velocity);
        //    }
        //}
#endif

        public void Update(GameTime gameTime)
        {
            if (newState != null)
            {
                LastScrollPos = newState.ScrollPos;

                oldState = newState.CloneMe();
            }
            else
            {
                newState = new BreezeInputState();
            }

            // newState = new BreezeInputState();
            newState.UpdateState();
            MousePosition = newState.MousePosition;
            if (MousePosition != PreviousMousePosition)
            {
                MouseActive = true;
            }

            PreviousMousePosition = MousePosition;

            MouseScreenPosition = new Vector2(newState.MousePosition.X / Solids.Instance.SpriteBatch.GraphicsDevice.Viewport.Bounds.Width, newState.MousePosition.Y / Solids.Instance.SpriteBatch.GraphicsDevice.Viewport.Bounds.Height);

            bool?mba = newState.ShouldMouseBeActive();

            if (mba != null)
            {
                MouseActive = mba.Value;
            }

            //---------------------------------

            CurrentStack = new InputStack();

            var currentKeyState = Keyboard.GetState();

            GamePadState[] currentGamePadState = new GamePadState[GamePad.MaximumGamePadCount];

            List <Buttons> currentButtons = new List <Buttons>();

            for (int i = 0; i < GamePad.MaximumGamePadCount; i++)
            {
                currentGamePadState[i] = GamePad.GetState(i);

                foreach (Buttons b in Enum.GetValues(typeof(Buttons)))
                {
                    if (currentGamePadState[i].IsButtonDown(b))
                    {
                        currentButtons.Add(b);
                        MouseActive = false;
                    }
                }
            }

            var justPressedButtons  = currentButtons.Where(x => !previousButtons.Contains(x));
            var justReleasedButtons = previousButtons.Where(x => !currentButtons.Contains(x));
            var heldButtons         = previousButtons.Where(x => currentButtons.Contains(x));
            var notPressedButtons   = PossibleGamePadButtons.Where(x => !currentButtons.Contains(x));

            foreach (Buttons justPressedKey in justPressedButtons)
            {
                holdCounter.Add("GPB_" + justPressedKey.ToString(), 0);
                CurrentStack.Inputs.Add(new GamepadControl(justPressedKey, PressType.Press));
                CurrentStack.Inputs.Add(new GamepadControl(justPressedKey, PressType.PressThenHolding));
            }

            foreach (Buttons heldKey in heldButtons)
            {
                holdCounter["GPB_" + heldKey.ToString()]++;

                if (holdCounter["GPB_" + heldKey.ToString()] == SHORTHOLD)
                {
                    CurrentStack.Inputs.Add(new GamepadControl(heldKey, PressType.HoldingTriggered));
                }

                if (holdCounter["GPB_" + heldKey.ToString()] > LONGHOLD + LONGHOLDREPEAT)
                {
                    CurrentStack.Inputs.Add(new GamepadControl(heldKey, PressType.LongHoldingRepeat));
                    holdCounter["GPB_" + heldKey.ToString()] = LONGHOLD + 1;
                }


                if (holdCounter["GPB_" + heldKey.ToString()] > LONGHOLD)
                {
                    CurrentStack.Inputs.Add(new GamepadControl(heldKey, PressType.LongHolding));
                }

                if (holdCounter["GPB_" + heldKey.ToString()] > SHORTHOLD)
                {
                    CurrentStack.Inputs.Add(new GamepadControl(heldKey, PressType.Holding));
                    CurrentStack.Inputs.Add(new GamepadControl(heldKey, PressType.PressThenHolding));
                }
            }

            foreach (Buttons justReleasedKey in justReleasedButtons)
            {
                if (holdCounter["GPB_" + justReleasedKey.ToString()] < SHORTHOLD)
                {
                    CurrentStack.Inputs.Add(new GamepadControl(justReleasedKey, PressType.Tap));
                }
                else
                {
                    CurrentStack.Inputs.Add(new GamepadControl(justReleasedKey, PressType.LongTapped));
                }

                CurrentStack.Inputs.Add(new GamepadControl(justReleasedKey, PressType.Released));

                holdCounter.Remove("GPB_" + justReleasedKey.ToString());
            }

            foreach (Buttons notPressed in notPressedButtons)
            {
                CurrentStack.Inputs.Add(new GamepadControl(notPressed, PressType.NotPressed));
            }

            previousButtons = currentButtons.ToArray().ToList();

            List <MouseButtons> currentMouseButtons = new List <MouseButtons>();

            if (newState.VirtualMouse.PrimaryDown)
            {
                currentMouseButtons.Add(MouseButtons.LeftClick);
            }
            if (newState.VirtualMouse.SecondaryDown)
            {
                currentMouseButtons.Add(MouseButtons.RightClick);
            }
            if (newState.VirtualMouse.MiddleDown)
            {
                currentMouseButtons.Add(MouseButtons.MiddleClick);
            }


#if WINDOWS_UAP
            //if (state.HorizontalScrollWheelValue < previousMouseState.HorizontalScrollWheelValue)
            //{
            //    currentMouseButtons.Add(MouseButtons.MouseWheelUp);
            //}

            //if (state.HorizontalScrollWheelValue > previousMouseState.HorizontalScrollWheelValue)
            //{
            //    currentMouseButtons.Add(MouseButtons.MouseWheelDown);
            //}
#endif

            var justPressedMouseButtons  = currentMouseButtons.Where(x => previousMouseButtons.Contains(x) == false);
            var justReleasedMouseButtons = previousMouseButtons.Where(x => currentMouseButtons.Contains(x) == false);
            var heldMouseButtons         = currentMouseButtons.Where(x => previousMouseButtons.Contains(x));
            var notPressedMouseButtons   = PossibleMouseButtons.Where(x => !currentMouseButtons.Contains(x));

            foreach (MouseButtons notPressedMouseButton in notPressedMouseButtons)
            {
                CurrentStack.Inputs.Add(new MouseControl(notPressedMouseButton, PressType.NotPressed));
            }

            foreach (MouseButtons justPressedKey in justPressedMouseButtons)
            {
                holdCounter.Add("MB_" + justPressedKey.ToString(), 0);
                CurrentStack.Inputs.Add(new MouseControl(justPressedKey, PressType.Press));
                CurrentStack.Inputs.Add(new MouseControl(justPressedKey, PressType.PressThenHolding));
                MouseActive = true;
            }

            foreach (MouseButtons heldKey in heldMouseButtons)
            {
                holdCounter["MB_" + heldKey.ToString()]++;

                CurrentStack.Inputs.Add(new MouseControl(heldKey, PressType.Held));

                if (holdCounter["MB_" + heldKey.ToString()] == SHORTHOLD)
                {
                    CurrentStack.Inputs.Add(new MouseControl(heldKey, PressType.HoldingTriggered));
                }

                if (holdCounter["MB_" + heldKey.ToString()] > LONGHOLD + LONGHOLDREPEAT)
                {
                    CurrentStack.Inputs.Add(new MouseControl(heldKey, PressType.LongHoldingRepeat));
                    holdCounter["MB_" + heldKey.ToString()] = LONGHOLD + 1;
                }


                if (holdCounter["MB_" + heldKey.ToString()] > LONGHOLD)
                {
                    CurrentStack.Inputs.Add(new MouseControl(heldKey, PressType.LongHolding));
                }
                // else
                {
                    if (holdCounter["MB_" + heldKey.ToString()] > SHORTHOLD)
                    {
                        CurrentStack.Inputs.Add(new MouseControl(heldKey, PressType.Holding));
                        CurrentStack.Inputs.Add(new MouseControl(heldKey, PressType.PressThenHolding));
                    }
                }
            }

            foreach (MouseButtons justReleasedKey in justReleasedMouseButtons)
            {
                Console.WriteLine(holdCounter["MB_" + justReleasedKey.ToString()]);
                if (holdCounter["MB_" + justReleasedKey.ToString()] < SHORTHOLD)
                {
                    CurrentStack.Inputs.Add(new MouseControl(justReleasedKey, PressType.Tap));
                }
                else
                {
                    CurrentStack.Inputs.Add(new MouseControl(justReleasedKey, PressType.LongTapped));
                }

                CurrentStack.Inputs.Add(new MouseControl(justReleasedKey, PressType.Released));

                holdCounter.Remove("MB_" + justReleasedKey.ToString());
            }

            previousMouseButtons = currentMouseButtons.ToArray().ToList();


            var currentKeys      = currentKeyState.GetPressedKeys();
            var previousKeys     = previousKeyState.GetPressedKeys();
            var justPressedKeys  = currentKeys.Where(x => previousKeys.Contains(x) == false);
            var justReleasedKeys = previousKeys.Where(x => currentKeys.Contains(x) == false);
            var heldKeys         = currentKeys.Where(x => previousKeys.Contains(x));
            var notPressedKeys   = PossibleKeyboardKeys.Where(x => !currentKeys.Contains(x));

            foreach (var notPressedKey in notPressedKeys)
            {
                CurrentStack.Inputs.Add(new KeyboardControl(notPressedKey, PressType.NotPressed));
            }

            foreach (Keys justPressedKey in justPressedKeys)
            {
                holdCounter.Add("Key_" + justPressedKey.ToString(), 0);
                CurrentStack.Inputs.Add(new KeyboardControl(justPressedKey, PressType.Press));
            }

            foreach (Keys heldKey in heldKeys)
            {
                holdCounter["Key_" + heldKey.ToString()]++;

                if (holdCounter["Key_" + heldKey.ToString()] == SHORTHOLD)
                {
                    CurrentStack.Inputs.Add(new KeyboardControl(heldKey, PressType.HoldingTriggered));
                }

                if (holdCounter["Key_" + heldKey.ToString()] > LONGHOLD + LONGHOLDREPEAT)
                {
                    CurrentStack.Inputs.Add(new KeyboardControl(heldKey, PressType.LongHoldingRepeat));
                    holdCounter["Key_" + heldKey.ToString()] = LONGHOLD + 1;
                }


                if (holdCounter["Key_" + heldKey.ToString()] > LONGHOLD)
                {
                    CurrentStack.Inputs.Add(new KeyboardControl(heldKey, PressType.LongHolding));
                }
                //   else
                {
                    if (holdCounter["Key_" + heldKey.ToString()] > SHORTHOLD)
                    {
                        CurrentStack.Inputs.Add(new KeyboardControl(heldKey, PressType.Holding));
                    }
                }
            }

            foreach (Keys justReleasedKey in justReleasedKeys)
            {
                if (holdCounter["Key_" + justReleasedKey.ToString()] < SHORTHOLD)
                {
                    CurrentStack.Inputs.Add(new KeyboardControl(justReleasedKey, PressType.Tap));
                }
                else
                {
                    CurrentStack.Inputs.Add(new KeyboardControl(justReleasedKey, PressType.LongTapped));
                }

                CurrentStack.Inputs.Add(new KeyboardControl(justReleasedKey, PressType.Released));

                holdCounter.Remove("Key_" + justReleasedKey.ToString());
            }

            previousKeyState = currentKeyState;
        }
Ejemplo n.º 22
0
 private void SwapNodes(int indexA, int indexB)
 {
     Inputs.Swap(indexA, indexB);
     InputStack.SwapChildren(indexA, indexB);
     InputsChanged?.Invoke(this, null);
 }