我有一个IObservable<InputEvent> eventStream
表示键盘输入流(KeyUp 或 KeyDown)的流。通过应用Window 运算符,我可以隔离保持输入的持续时间:
public static IObservable<InputEvent> WhileHeld(this IObservable<InputEvent> source, String key) {
var k = source.Where(i => i.Key == key);
return source.Window(k.Press(), _ => k.Release()).Switch().Where(i => i.Key != key);
}
我现在想做的是找到多个窗口的“重叠”。例如:
var ctrlHeld = eventStream.WhileHeld("ctrl");
var shiftHeld = eventStream.WhileHeld("shift");
我想应用一个运算符来查找这两个序列之间的重叠,如下面的大理石图所示
- K = 事件类型,其中
.
是新闻,'
是发布 - 我 = 事件流
- C = eventStream.WhileHeld("ctrl")
- S = eventStream.WhileHeld("shift")
- r = 结果流
大理石:
K |--.---.-.-.-'-'---.-.-.-'-'---.-.-'-.-.-.-'
i |--a---C-S-b-S-C---C-S-c-C-S---C-S-S-d-S-e-C-
C |--------S-b-S-------S-c---------S-S-d-S-e---
S |----------b-----------c-C---------------e-C
r |----------b-----------c-----------------e---
这样的运营商存在吗?或者它将如何组成?
编辑:
为了帮助可视化实际的事件流(我意识到上面的大理石图有点复杂)。这是我的事件流测试代码:
eventStream.Pump("a", EventType.Down); // should not propagate
eventStream.Pump("ctrl", EventType.Down);
eventStream.Pump("shift", EventType.Down);
eventStream.Pump("b", EventType.Down); // should propagate
eventStream.Pump("shift", EventType.Up);
eventStream.Pump("ctrl", EventType.Up);
eventStream.Pump("ctrl", EventType.Down);
eventStream.Pump("shift", EventType.Down);
eventStream.Pump("c", EventType.Down); // should propagate
eventStream.Pump("ctrl", EventType.Up);
eventStream.Pump("shift", EventType.Up);
eventStream.Pump("ctrl", EventType.Down);
eventStream.Pump("shift", EventType.Down);
eventStream.Pump("shift", EventType.Up);
eventStream.Pump("d", EventType.Down); // should not propagate
eventStream.Pump("shift", EventType.Down);
eventStream.Pump("e", EventType.Down); // should propagate
eventStream.Pump("ctrl", EventType.Up);