• 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 lunardiplomacy, Today, 08:23 AM
      1 response
      6 views
      0 likes
      Last Post NinjaTrader_Jesse  
      Started by Gerik, Today, 06:36 AM
      1 response
      6 views
      0 likes
      Last Post NinjaTrader_Kate  
      Started by swcooke, Yesterday, 03:31 PM
      3 responses
      27 views
      0 likes
      Last Post MojoJojo  
      Started by swcooke, Yesterday, 04:29 PM
      1 response
      9 views
      0 likes
      Last Post NinjaTrader_Jesse  
      Started by ttodua, Today, 06:51 AM
      0 responses
      5 views
      0 likes
      Last Post ttodua
      by ttodua
       
      Working...
      X