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

Send Keyboard Event. "open sesame"?

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

    Send Keyboard Event. "open sesame"?

    Forum support folks have several times recommended the technique below for sending keyboard events from a script. However, I have no idea what "open sesame" refers to nor what I would put in its place in order to:

    1) Open the Data Series dialogue.
    2) Change the bar period (specifically Renko brick size).

    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.


    Thanks for any clues you can give.

    #2
    Hello gbourque,

    This would be a string used to open the Instrument Overlay. (Any string will do here)

    Note, the script you have linked uses code that is not supported by NinjaTrader and is not documented in the help guide.
    Chelsea B.NinjaTrader Customer Service

    Comment


      #3
      I see you are the writer of the script, so I'm in good hands. So the Enter key code in your script is an example of how to send a particular event. Correct?

      Comment


        #4
        Hello gbourque,

        This invokes the enter key in the instrument overlay window, which will trigger the instrument and / or data series to load, the same as if you had pressed enter on the keyboard while the instrument overlay window is open.
        Chelsea B.NinjaTrader Customer Service

        Comment


          #5
          Okay. So let me ask you... My indicator is running in a Renko chart, I want the chart to, when the instrument symbol changes, to change the bar period (Renko brick size). I want to use the technique in your script to do this. What would change in your code to make this happen? Thanks.

          Comment


            #6
            Hello gbourque,

            Please note, this would not be under the realm of what is supported by the NinjaTrader support team.

            This would be something that should be used at your own risk, and may require further custom c#.

            That said, nextExpiryString is the string being sent to the instrument overlay window. Your string would be "4RE" to change to 4 renko.
            Chelsea B.NinjaTrader Customer Service

            Comment


              #7
              I get it now. The "instrument overlay window" is that black overlay that pops up when you press certain keys. I didn't understand that before.

              Yes, that worked. Thanks! I understand that this is unsupported and the risk is mine.

              // 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.Prim aryKeyboardDevice,
              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.Prim aryKeyboardDevice,
              new TextComposition(InputManager.Current, ChartControl.OwnerChart, "40RE"))
              { RoutedEvent = TextCompositionManager.TextInputEvent });

              // send Enter key
              Keyboard.FocusedElement.RaiseEvent(new KeyEventArgs(Keyboard.PrimaryDevice,
              PresentationSource.FromVisual(ChartControl.OwnerCh art), 0, Key.Enter) { RoutedEvent = Keyboard.PreviewKeyDownEvent } );

              Comment


                #8
                Just an FYI, it started getting this error on the keyboard code:

                Error on calling 'OnStateChange' method: The calling thread must be STA, because many UI components require this.

                So I wrapped the keyboard code (see previous post) in the method CallKeyboard() and called it like this:

                ChartControl.Dispatcher.InvokeAsync((Action)(() =>
                {
                CallKeyboard(brickSize);
                }));

                That seems to have fixed it.

                Comment


                  #9
                  Nope. The code blew away another indicator in my chart. Apparently, this code must run from a UI thread. I need it to run from StateChange.

                  Comment

                  Latest Posts

                  Collapse

                  Topics Statistics Last Post
                  Started by jxs_xrj, 01-12-2020, 09:49 AM
                  6 responses
                  3,290 views
                  1 like
                  Last Post jgualdronc  
                  Started by Touch-Ups, Today, 10:36 AM
                  0 responses
                  8 views
                  0 likes
                  Last Post Touch-Ups  
                  Started by geddyisodin, 04-25-2024, 05:20 AM
                  11 responses
                  61 views
                  0 likes
                  Last Post halgo_boulder  
                  Started by Option Whisperer, Today, 09:55 AM
                  0 responses
                  8 views
                  0 likes
                  Last Post Option Whisperer  
                  Started by halgo_boulder, 04-20-2024, 08:44 AM
                  2 responses
                  24 views
                  0 likes
                  Last Post halgo_boulder  
                  Working...
                  X