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("{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.
        Emily C.NinjaTrader Customer Service

        Comment


          #5
          Thank you all !!!

          Comment

          Latest Posts

          Collapse

          Topics Statistics Last Post
          Started by fx.practic, 10-15-2013, 12:53 AM
          5 responses
          5,404 views
          0 likes
          Last Post Bidder
          by Bidder
           
          Started by Shai Samuel, 07-02-2022, 02:46 PM
          4 responses
          95 views
          0 likes
          Last Post Bidder
          by Bidder
           
          Started by DJ888, Yesterday, 10:57 PM
          0 responses
          8 views
          0 likes
          Last Post DJ888
          by DJ888
           
          Started by MacDad, 02-25-2024, 11:48 PM
          7 responses
          159 views
          0 likes
          Last Post loganjarosz123  
          Started by Belfortbucks, Yesterday, 09:29 PM
          0 responses
          8 views
          0 likes
          Last Post Belfortbucks  
          Working...
          X