public IEnumerable <IInputCallbacker> Update(Dictionary <Type, IInputStateProvider> providers, GameTime gt) { KeyboardStateProvider keyInput = (KeyboardStateProvider)providers[typeof(KeyboardStateProvider)]; //Console.WriteLine(keyInput.IsKeyDown(Keys.Space)); Keys[] newKeys = keyInput.CurrentState.GetPressedKeys(); Keys[] oldKeys = keyInput.OldState.GetPressedKeys(); IEnumerable <Keys> toCheck = oldKeys.Union(newKeys); List <String> calls = new List <string>(); foreach (Keys key in toCheck) { foreach (var bind in keyBinds.Where(bind => bind.Value.Contains(key))) { if (calls.Contains(bind.Key)) { continue; } KeyboardBinding binding = Bindings[bind.Key]; InputState inputState = InputState.Up; // koska key on down useimmiten, niin parempi tarkastaa eka if (keyInput.IsKeyDown(key)) { inputState = InputState.Down; binding.HoldTime += gt.ElapsedGameTime.TotalMilliseconds; } // just tällä framella else if (keyInput.IsKeyPressed(key)) { inputState = InputState.Pressed; binding.HoldTime = 0; } // just löysätty else if (keyInput.IsKeyReleased(key)) { inputState = InputState.Released; } if ((inputState & binding.Condition) != inputState) { continue; } InputEventArgs args = new InputEventArgs(binding.HoldTime, inputState, gt); KeyboardInputCallbacker cb = new KeyboardInputCallbacker(key, args, binding.Callbacks); calls.Add(bind.Key); yield return(cb); } } }
public IEnumerable<IInputCallbacker> Update(Dictionary<Type, IInputStateProvider> providers, GameTime gt) { KeyboardStateProvider keyInput = (KeyboardStateProvider)providers[typeof (KeyboardStateProvider)]; //Console.WriteLine(keyInput.IsKeyDown(Keys.Space)); Keys[] newKeys = keyInput.CurrentState.GetPressedKeys(); Keys[] oldKeys = keyInput.OldState.GetPressedKeys(); IEnumerable<Keys> toCheck = oldKeys.Union(newKeys); List<String> calls = new List<string>(); foreach (Keys key in toCheck) { foreach (var bind in keyBinds.Where(bind => bind.Value.Contains(key))) { if (calls.Contains(bind.Key)) continue; KeyboardBinding binding = Bindings[bind.Key]; InputState inputState = InputState.Up; // koska key on down useimmiten, niin parempi tarkastaa eka if (keyInput.IsKeyDown(key)) { inputState = InputState.Down; binding.HoldTime += gt.ElapsedGameTime.TotalMilliseconds; } // just tällä framella else if (keyInput.IsKeyPressed(key)) { inputState = InputState.Pressed; binding.HoldTime = 0; } // just löysätty else if (keyInput.IsKeyReleased(key)) { inputState = InputState.Released; } if ((inputState & binding.Condition) != inputState) continue; InputEventArgs args = new InputEventArgs(binding.HoldTime, inputState, gt); KeyboardInputCallbacker cb = new KeyboardInputCallbacker(key, args, binding.Callbacks); calls.Add(bind.Key); yield return cb; } } }