tmn
tmn

Reputation: 11559

ReactFX- How do I create a stream for CTRL-C key combination event?

I'm new to ReactFX and I'm trying to capture the CTRL and C keys being pressed for a typical copy operation.

How do I capture this effectively into a stream? This is all I could get so far but it is not even compiling...

final EventStream<KeyEvent> keysTyped = EventStreams.eventsOf(myTbl, KeyEvent.KEY_TYPED)
        .reduceSuccessions((a,b) -> new KeyCodeCombination(a.getCode(),b.getCode()), 500);

Upvotes: 1

Views: 392

Answers (1)

James_D
James_D

Reputation: 209340

This works for me:

    KeyCombination ctrlC = new KeyCodeCombination(KeyCode.C, KeyCombination.SHORTCUT_DOWN);
    final EventStream<KeyEvent> keysTyped = EventStreams.eventsOf(text, KeyEvent.KEY_PRESSED)
            // the following line, if uncommented, will limit the frequency
            // of processing ctrl-C to not more than once every 0.5 seconds
            // As a side-effect, processing will be delayed by the same amount
            // .reduceSuccessions((a, b) -> b, Duration.ofMillis(500))
            .filter(ctrlC::match);
    keysTyped.subscribe(event -> System.out.println("Ctrl-C pressed!"));

Upvotes: 1

Related Questions