Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

SendKeys("{F5}");

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

    SendKeys("{F5}");

    Why the following code line
    System.Windows.Forms.SendKeys("{F5}");
    produces a compiling error :
    "'System.Windows.Forms.SendKeys' is a 'type', which is not valid in the given context"
    Thank you.

    #2
    Originally posted by giogio1 View Post
    Why the following code line
    System.Windows.Forms.SendKeys("{F5}");
    produces a compiling error :
    "'System.Windows.Forms.SendKeys' is a 'type', which is not valid in the given context"
    Thank you.
    The message means exactly what it says. You can't call a type like that - you can only call a method. The reason you can't call System.Windows.Forms.SendKeys("TEST") is the same reason you can't call System.Windows.Forms("TEST") - those are the names of namespaces or classes but not names of methods.

    Bruce DeVault
    QuantKey Trading Vendor Services
    NinjaTrader Ecosystem Vendor - QuantKey

    Comment


      #3
      What you probably mean to do is SendKeys.SendWait("{F5}") but it would be better if you would follow the approach NinjaTrader_ChelseaB uses in the excellent example app RolloverIndications that handles this type of thing much more thoroughly and with less chance of error:
      Code:
              private void RolloverBtn_Click(object sender, RoutedEventArgs e)
              {
                  // 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);
                  // explicitly remove the focus from the button
                  FocusManager.SetFocusedElement(scope, null);
                  // remove keyboard focus
                  Keyboard.ClearFocus();
      
                  // explicity give the chart focus
                  ChartControl.OwnerChart.Focus();
      
                  // send a key event to trigger the instrument overlay selector to appear
                  Keyboard.FocusedElement.RaiseEvent(new TextCompositionEventArgs(InputManager.Current.PrimaryKeyboardDevice,
                          new TextComposition(InputManager.Current, ChartControl.OwnerChart, "open sesame"))
                              { RoutedEvent = TextCompositionManager.PreviewTextInputEvent });
      
                  // send the actual string you want in the instrument overlay selector
                  Keyboard.FocusedElement.RaiseEvent(new TextCompositionEventArgs(InputManager.Current.PrimaryKeyboardDevice,
                          new TextComposition(InputManager.Current, ChartControl.OwnerChart, nextExpiryString))
                              { RoutedEvent = TextCompositionManager.TextInputEvent });
      
                  // optionally send the enter key
                  if (!Prompt)
                      Keyboard.FocusedElement.RaiseEvent(new KeyEventArgs(Keyboard.PrimaryDevice,
                              PresentationSource.FromVisual(ChartControl.OwnerChart), 0,  Key.Enter) { RoutedEvent = Keyboard.PreviewKeyDownEvent } );
              }​
      Bruce DeVault
      QuantKey Trading Vendor Services
      NinjaTrader Ecosystem Vendor - QuantKey

      Comment


        #4
        Hello giogio1,

        Thank you for your post.

        SendKeys is not officially supported by the NinjaScript support team. That said, this thread will remain open in case any community members, like Bruce, would like to chime in.

        You could check out the RolloverIndications indicator - it sends key commands from a button press on the toolbar. This indicator is publicly available on our NinjaTrader Ecosystem website:
        Please let me know if I can be of further assistance.

        The NinjaTrader Ecosystem website is for educational and informational purposes only and should not be considered a solicitation to buy or sell a futures contract or make any other type of investment decision. The add-ons listed on this website are not to be considered a recommendation and it is the reader's responsibility to evaluate any product, service, or company. NinjaTrader Ecosystem LLC is not responsible for the accuracy or content of any product, service or company linked to on this website.

        Comment


          #5
          Thank you all !!!

          Comment

          Latest Posts

          Collapse

          Topics Statistics Last Post
          Started by Geovanny Suaza, 02-11-2026, 06:32 PM
          0 responses
          557 views
          0 likes
          Last Post Geovanny Suaza  
          Started by Geovanny Suaza, 02-11-2026, 05:51 PM
          0 responses
          324 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
          545 views
          1 like
          Last Post Geovanny Suaza  
          Started by RFrosty, 01-28-2026, 06:49 PM
          0 responses
          547 views
          1 like
          Last Post RFrosty
          by RFrosty
           
          Working...
          X