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 andrewtrades, Today, 04:57 PM
      1 response
      8 views
      0 likes
      Last Post NinjaTrader_Manfred  
      Started by chbruno, Today, 04:10 PM
      0 responses
      6 views
      0 likes
      Last Post chbruno
      by chbruno
       
      Started by josh18955, 03-25-2023, 11:16 AM
      6 responses
      436 views
      0 likes
      Last Post Delerium  
      Started by FAQtrader, Today, 03:35 PM
      0 responses
      7 views
      0 likes
      Last Post FAQtrader  
      Started by rocketman7, Today, 09:41 AM
      5 responses
      19 views
      0 likes
      Last Post NinjaTrader_Jesse  
      Working...
      X