Frage

Dynamic Evaluations in a Key Listener

public class KeyUpper {
    Func<Key, bool> _evaluate;

    public void RegisterEvaluator(Func<Key, bool> evaluate){
        _evaluate = evaluate;
    }

    public void KeyUp(object sender, KeyEventArgs e){
        if (_evaluate(e.KeyCode))
            SomeResponse();
    }

    public void SomeResponse(){
        // ...
    }
}

This Lambda Should Await on Each Line

keyUpper.RegisterEvaluator(key => 
    {
    if (key == Key.A)
        if (key == Key.W)
            if (key == Key.A)
                return true;
    }
);
  • i.e. client code would provide a series of evaluations on the same key argument with the expectation that each line of evaluation would be awaited so that SomeResponse() would be invoked after a sequence of keyup events of 1:A 2:W 3:A
  • obviously at the moment that will never happen because the method is run until the end and key == Key.W will never be true
  • it may not be possible, but is there a way to make the method invocation automagically return from the next line if it evaluates to false but return to it until that line evaluates to true, following that through to the line after that, and to the line after that until the end of the method?
  • i.e. might there be a simple way to provide awaitable lambda expressions of this kind?

Keine korrekte Lösung

Lizenziert unter: CC-BY-SA mit Zuschreibung
Nicht verbunden mit StackOverflow
scroll top