Announcement

Collapse

Looking for a User App or Add-On built by the NinjaTrader community?

Visit NinjaTrader EcoSystem and our free User App Share!

Have a question for the NinjaScript developer community? Open a new thread in our NinjaScript File Sharing Discussion Forum!
See more
See less

Partner 728x90

Collapse

SendKeys("{LEFT}") don't work from button handler, while other keys work

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

    SendKeys("{LEFT}") don't work from button handler, while other keys work

    Hello.

    I want send keys {LEFT} and {RIGHT} using buttons.

    I tried to send these keys from OnBarUpdate() and OnStateChange() - works perfect.

    But, doesn't take any effect from buttons handlers (both grid and toollbar).

    Other keys I tested - work normally: {PGUP}, {PGDOWN}, even {CAPSLOCK} works fine!


    But, {LEFT}, {RIGHT}, {UP}, {DOWN} not work.

    I tried ChartControl.Dispatcher.InvokeAsync(), ChartControl.Dispatcher.Invoke(), TriggerCustomEvent() - no effect for arrow keys, while other keys work.

    Available keys on MSDN


    How to let arrow right work to get scroll effect?
    Attached Files
    Last edited by fx.practic; 01-28-2018, 05:16 PM.
    fx.practic
    NinjaTrader Ecosystem Vendor - fx.practic

    #2
    Hello fx.practic,

    Using SendKeys is not officially supported by NinjaScript Support.

    However, this thread will remain open for any community members that would like to assist.

    I would recommend taking a look at the RolloverIndications indicator which sends key commands from a button press on the toolbar.
    https://ninjatraderecosystem.com/user-app-share-download/rolloverindications-2/
    Last edited by NinjaTrader_ChelseaB; 04-18-2021, 07:40 PM.
    Chelsea B.NinjaTrader Customer Service

    Comment


      #3
      Thank You, Chelsea.


      RolloverIndications
      inspired me on chaotic researches and, I get some working code accidentally

      PHP Code:
                      C.Start_Stop_Button.Click += (sendere) => 
                      { 
                          
      System.Windows.Controls.Button button sender as System.Windows.Controls.Button;
                          if (
      button == null) return;                            
                          
                          
      // its possible for multiple items to have focus each within their own scope
                          // https://stackoverflow.com/questions/2052389/wpf-reset-focus-on-button-click

                          // get the scope of the button
                          //DependencyObject scope = FocusManager.GetFocusScope(rolloverButton); 
                          
      var Chart_Window Window.GetWindow(this.ChartControl.Parent) as Chart;
                          
      DependencyObject scope FocusManager.GetFocusScope(Chart_Window.MainMenu.LastOrDefault() as System.Windows.DependencyObject ); 
                          
                          
      // explicitly remove the focus from the button
                          
      FocusManager.SetFocusedElement(scopenull);
                          
      // remove keyboard focus
                          
      Keyboard.ClearFocus();

                          
      // explicity give the chart focus
                          
      ChartControl.OwnerChart.Focus();
                  
                          Print( 
      "" );    
                          Print( 
      "-------------------" );    
                          for( 
      int i 0<= 20i++ ) 
                          {
                              
      Keyboard.FocusedElement.RaiseEvent(new System.Windows.Input.KeyEventArgsKeyboard.PrimaryDevicePresentationSource.FromVisual(ChartControl.OwnerChart), 0,  Key.Right)    { RoutedEvent Keyboard.PreviewKeyDownEvent }  );
                              Print( 
      );    
                          }
                          Print( 
      "-------------------" );    
                          Print( 
      "" );    
                      }; 



      UPD: This code work from toolstrip button too.
      Attached Files
      Last edited by fx.practic; 01-29-2018, 07:54 AM.
      fx.practic
      NinjaTrader Ecosystem Vendor - fx.practic

      Comment

      Latest Posts

      Collapse

      Topics Statistics Last Post
      Started by jaybedreamin, Today, 05:56 PM
      0 responses
      2 views
      0 likes
      Last Post jaybedreamin  
      Started by DJ888, 04-16-2024, 06:09 PM
      6 responses
      18 views
      0 likes
      Last Post DJ888
      by DJ888
       
      Started by Jon17, Today, 04:33 PM
      0 responses
      1 view
      0 likes
      Last Post Jon17
      by Jon17
       
      Started by Javierw.ok, Today, 04:12 PM
      0 responses
      6 views
      0 likes
      Last Post Javierw.ok  
      Started by timmbbo, Today, 08:59 AM
      2 responses
      10 views
      0 likes
      Last Post bltdavid  
      Working...
      X