• If this is your first visit, you will have to register before you can post. To view messages, please scroll below and select the forum that you would like to visits. Questions? Be sure to check out the Forum FAQ.

Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Intercept keyboard event and trigger

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

    Intercept keyboard event and trigger

    Hi,

    after trying to implement something for a long time and failing to do so, unfortunately I have to ask for help.
    I hope somone can help me.

    My goal is to create a script to move the chart from the program.
    Since I did not find anything in the documentation, I would like to use C# Event, the
    Left and right arrow triggers.


    Code:
    protected override void OnStateChange()
    {
        if (State == State.DataLoaded)
        {
            this.ChartPanel.KeyDown += new System.Windows.Input.KeyEventHandler(OnKeyDown);          
        }
        else if (State == State.Terminated)
        {
            this.ChartPanel.KeyDown -= OnKeyDown;          
        }
    }
    
    public void OnKeyDown(object sender, System.Windows.Input.KeyEventArgs e)
    {   
        // detect Key (23 Left) and (25 Right)?
        Print("Down");     
    }
    example, not working


    Unfortunately, after 8 hours of programming, I am not getting anywhere.
    Can someone help me and tell me:

    A, how to intercept the keyboard event?
    B. That can act as a trigger?

    #2
    Hello,

    You can find a sample of using key events in the linked post below. As this is not NinjaScript specific you won't find much information about using WPF key events here on the forum or in the help guide. The best bet is to look for WPF samples online for specific concepts like this and then apply them in NinjaTrader.

    Because NinjaTrader is a WPF application that already has key events on the objects you are using, the PreviewKey events are generally needed to intercept key events. This is also not NinjaTrader specific but is standard with WPF design.
    https://ninjatrader.com/support/foru...973#post685973

    I look forward to being of further assistance.
    JesseNinjaTrader Customer Service

    Comment


      #3
      Thank you very much. Let's see what I can do

      Comment

      Latest Posts

      Collapse

      Topics Statistics Last Post
      Started by abdullah, 11-15-2017, 08:44 PM
      10 responses
      819 views
      0 likes
      Last Post Lancer
      by Lancer
       
      Started by brunoviveiros, Today, 04:31 AM
      2 responses
      13 views
      0 likes
      Last Post brunoviveiros  
      Started by foxy_rav, Today, 06:31 AM
      1 response
      4 views
      0 likes
      Last Post NinjaTrader_Jim  
      Started by neilzep, Today, 06:42 AM
      1 response
      5 views
      0 likes
      Last Post NinjaTrader_Jesse  
      Started by teafortwo, Today, 04:26 AM
      3 responses
      8 views
      0 likes
      Last Post NinjaTrader_PaulH  
      Working...
      X