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

Pressing ALT by itself triggers ChartPanel.MouseLeave()

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

    Pressing ALT by itself triggers ChartPanel.MouseLeave()

    I found a weird behavior that wanted NT to clarify if it is a bug or expected. I am a vendor and this behavior affects one of my indicators.

    In summary, with the mouse inside a focused chart, after pressing and releasing the ALT modifier key by itself, the ChartPanel.MouseLeave() callback is called. It is basically as if the mouse has left the chart, even though it is still within the chart panel.

    After this, moving the mouse within the panel does not call ChartPanel.MouseMove() anymore because it believes that the mouse pointer is outside the chart when in fact it's not. Only by pressing ALT again or by clicking on the chart triggers ChartPanel.MouseEnter(), which enables ChartPanel.MouseMove().

    The following code is a basic proof of concept to see this:

    Code:
    namespace NinjaTrader.NinjaScript.Indicators
    {
        public class ProofOfConcept : Indicator
        {
            private int counter = 0;
    
            protected override void OnStateChange()
            {
                if (State == State.SetDefaults)
                {
                    Name                                        = "ProofOfConcept";
                    Description                                 = @"Testing ChartPanel.MouseLeave and ChartPanel.MouseEnter";
                    Calculate                                   = Calculate.OnBarClose;
                    IsOverlay                                   = true;
                    DisplayInDataBox                            = false;
                    DrawOnPricePanel                            = true;
                    DrawHorizontalGridLines                     = true;
                    DrawVerticalGridLines                       = true;
                    PaintPriceMarkers                           = true;
                    ScaleJustification                          = ScaleJustification.Right;
                    //Disable this property if your indicator requires custom values that cumulate with each new market data event.
                    //See Help Guide for additional information.
                    IsSuspendedWhileInactive                    = true;
                }
                else if (State == State.Configure)
                {
                }
                 else if (State == State.Historical)
                  {    
                    if (ChartPanel != null)
                    {                
                        ChartPanel.MouseLeave += OnMouseLeave;
                        ChartPanel.MouseEnter += OnMouseEnter;
                        ChartPanel.MouseMove  += OnMouseMove;
                    }
                   }
                   else if (State == State.Terminated)
                   {
                    if (ChartPanel != null)
                    {
                        ChartPanel.MouseLeave -= OnMouseLeave;
                        ChartPanel.MouseEnter -= OnMouseEnter;
                        ChartPanel.MouseMove  -= OnMouseMove;
                    }
                   }
            }
    
            private void OnMouseEnter(object sender, MouseEventArgs e)
            {
                Print("OnMouseEnter");
            }
    
            private void OnMouseLeave(object sender, MouseEventArgs e)
            {
                Print("OnMouseLeave");
            }
    
            private void OnMouseMove(object sender, MouseEventArgs e)
            {
                if (counter++ % 10 == 0)
                    Print(string.Format("OnMouseMove: {0}", counter));
            }
        }
    }
    Just add it to a chart and with the mouse inside the chart in focus, press and release ALT. You should see something similar to this in NinjaScript Output:

    Code:
    OnMouseMove: 1
    OnMouseMove: 11
    OnMouseMove: 21
    OnMouseMove: 31
    OnMouseMove: 41
    OnMouseMove: 51
    OnMouseMove: 61
    OnMouseMove: 71
    OnMouseMove: 81
    OnMouseMove: 91
    OnMouseMove: 101
    OnMouseMove: 111
    OnMouseLeave
    Even with the mouse moving within the focused panel, there are no more OnMouseMove messages. Pressing and releasing ALT again triggers ChartPanel.MouseEnter()and things are back to normal.

    Is this expected behavior? If so, is there a workaround for this?

    I expected to received the MouseMove callback whenever the mouse moves inside the chart. This affects one of our indicators where ALT is used as a modifier key to see order previews on the chart.

    This is on NinjaTrader 8.0.26.1 64-bit.
    Last edited by VolatyTrading; 10-20-2022, 10:14 AM.

    #2
    HI VolatyTrading, thanks for posting. The Wikipedia on the Alt key describes the action Windows operating system takes when Alt is pressed on its own:

    "Alt key pressed alone
    When a user presses the Alt key by itself on Microsoft Windows, that moves keyboard focus to the menu bar of the application having keyboard focus, and the key is not delivered to the application. In that state, another press of the Alt key will be delivered to the application.​"

    You can see it happen on Notepad, where there is a File, Edit, Format, etc menu at the top of the application, pressing Alt will remove the focus. Alt might not be the best modifier key to use, although there are most likely workarounds e.g. ignoring the default action of Alt. Unfortunately, this goes outside of the scope of support I can provide on the subject, so you will need to research how to change the default behavior of the Alt key in a Windows/.NET/C# based application or use a different modifier.

    Kind regards,
    -ChrisL
    Chris L.NinjaTrader Customer Service

    Comment


      #3
      NinjaTrader_ChrisL thanks for the clarification!

      Comment

      Latest Posts

      Collapse

      Topics Statistics Last Post
      Started by reynoldsn, Today, 07:23 AM
      4 responses
      9 views
      1 like
      Last Post reynoldsn  
      Started by bee1943, Today, 09:55 AM
      1 response
      13 views
      0 likes
      Last Post NinjaTrader_ChelseaB  
      Started by FAQtrader, 04-25-2024, 12:00 PM
      7 responses
      101 views
      0 likes
      Last Post NinjaTrader_ChelseaB  
      Started by giulyko00, Yesterday, 11:49 AM
      4 responses
      28 views
      0 likes
      Last Post giulyko00  
      Started by Sebastian - TwinPeaks, Yesterday, 01:31 PM
      4 responses
      26 views
      0 likes
      Last Post Sebastian - TwinPeaks  
      Working...
      X