Dukascopy
 
 
Wiki JStore Search Login

Attention! Read the forum rules carefully before posting a topic.

    Try to find an answer in Wiki before asking a question.
    Submit programming questions in this forum only.
    Off topics are strictly forbidden.

Any topics which do not satisfy these rules will be deleted.

Keyboard input
 Post subject: Keyboard input Post rating: 0   New post Posted: Wed 29 May, 2019, 09:35 

User rating: 2
Joined: Thu 01 Mar, 2012, 17:17
Posts: 42
I've been trying to use the wiki code for getting keyboard input at
https://www.dukascopy.com/wiki/en/devel ... ard-events

It runs quite OK, but the key event dispatcher persists after the strategy is stopped and even after the strategy is removed from the active strategies list. The only way to get it to recognize any changes to the code is thus to close and reopen JForex. Would it be possible to fix this?

Many thanks, Bunyip


 
 Post subject: Re: Keyboard input Post rating: 0   New post Posted: Thu 30 May, 2019, 12:32 
User avatar

User rating:
Joined: Fri 31 Aug, 2007, 09:17
Posts: 6139
Hello,

You can initialize KeyEventDispatcher as a class variable. And then in onStop() method remove your eventDispatcher from KeyboardFocusManager. Then Key Events control will be returned to default dispatcher.

private KeyEventDispatcher eventDispatcher;

    @Override
    public void onStart(IContext context) throws JFException {
        this.engine = context.getEngine();
        this.console = context.getConsole();
        this.history = context.getHistory();
        this.context = context;
        this.indicators = context.getIndicators();
        this.userInterface = context.getUserInterface();

        eventDispatcher = event -> {
            boolean discardEvent = false;

            int closeMAsk = KeyEvent.CTRL_DOWN_MASK + 82;

            if (((event.getModifiersEx() + event.getKeyCode()) == closeMAsk)
                    && event.paramString().indexOf("KEY_PRESSED") >= 0) {
                console.getOut().println("ctrl-r pressed");
                context.executeTask(new OnKeyTask());
                discardEvent = true;
            }

            return discardEvent;
        };

        KeyboardFocusManager.getCurrentKeyboardFocusManager().addKeyEventDispatcher(eventDispatcher);
    }

    @Override
    public void onStop() throws JFException {
        KeyboardFocusManager.getCurrentKeyboardFocusManager().removeKeyEventDispatcher(eventDispatcher);
    }


 
 Post subject: Re: Keyboard input Post rating: 0   New post Posted: Fri 31 May, 2019, 21:23 

User rating: 2
Joined: Thu 01 Mar, 2012, 17:17
Posts: 42
Many thanks! That works just fine.


 

Jump to:  

  © 1998-2024 Dukascopy® Bank SA
On-line Currency forex trading with Swiss Forex Broker - ECN Forex Brokerage,
Managed Forex Accounts, introducing forex brokers, Currency Forex Data Feed and News
Currency Forex Trading Platform provided on-line by Dukascopy.com