Announcement

Collapse
No announcement yet.

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 += (sender, e) => 
                      { 
                          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(scope, null);
                          // remove keyboard focus
                          Keyboard.ClearFocus();
      
                          // explicity give the chart focus
                          ChartControl.OwnerChart.Focus();
                  
                          Print( "" );    
                          Print( "-------------------" );    
                          for( int i = 0; i <= 20; i++ ) 
                          {
                              Keyboard.FocusedElement.RaiseEvent(new System.Windows.Input.KeyEventArgs( Keyboard.PrimaryDevice, PresentationSource.FromVisual(ChartControl.OwnerChart), 0,  Key.Right)    { RoutedEvent = Keyboard.PreviewKeyDownEvent }  );
                              Print( i );    
                          }
                          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 Geovanny Suaza, 02-11-2026, 06:32 PM
      0 responses
      571 views
      0 likes
      Last Post Geovanny Suaza  
      Started by Geovanny Suaza, 02-11-2026, 05:51 PM
      0 responses
      330 views
      1 like
      Last Post Geovanny Suaza  
      Started by Mindset, 02-09-2026, 11:44 AM
      0 responses
      101 views
      0 likes
      Last Post Mindset
      by Mindset
       
      Started by Geovanny Suaza, 02-02-2026, 12:30 PM
      0 responses
      548 views
      1 like
      Last Post Geovanny Suaza  
      Started by RFrosty, 01-28-2026, 06:49 PM
      0 responses
      548 views
      1 like
      Last Post RFrosty
      by RFrosty
       
      Working...
      X