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

OnKeyDown does not fire coming from lost focus window

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

    OnKeyDown does not fire coming from lost focus window

    I use the OnKeyDown method in an indicator which works fine until the chart window has lost focus. I tried forcing focus to the window and chart panel using chartWindow.Focus() and ChartPanel.Focus() when the mouse moves over the chart window. But the key down event still does not trigger until I left click on the chart panel. Is there a way I can get the key down method to fire when the mouse is on the chart panel?

    #2
    Hello martyn73,

    Thank you for your post.

    In general, what you are describing would be expected of any C# program, if the window becomes out of focus, key events would be routed to whatever is now in focus.

    Have you tried focusing the ChartControl rather than the window? We don't have any guidelines surrounding focusing a window in the platform as the windows are multi-part, I can say that if you have an instance to the control you are trying to send keys to, a better approach may be to use routed events or the automation framework in WPF if possible.

    I look forward to being of further assistance.
    JesseNinjaTrader Customer Service

    Comment


      #3
      Focusing the ChartControl did not help. I'm trying to determine if the shift key is pressed when the mouse if over the chart. I can easily do this using PreviewMouseMove mouse event handler. But this does not work if the mouse is over the chart but not moving and the chart panel has not been clicked and focused. Because in that case the OnKeyDown nor PreviewMouseMove triggers.

      Are you referring to using a global key hook? Do you have any examples available? Thanks.

      Comment


        #4
        Hello martyn73,

        Yes, I would not expect this to work unless the control you are trying to target is focused, otherwise, the various events you are trying to capture would not be routed to that control. You would need to focus the control in question prior to doing your logic in the preview event however I am unsure of any documented NinjaScript methods to focus a specific window in a supported way.

        Controlling focus in an application is mainly a C#/WPF concept, so this may be something you can research externally for alternative ideas on focusing the control. You can also search this forum for specific topics such as the names of the Preview events you used to find where other users have explored these concepts.

        Are you referring to using a global key hook? Do you have any examples available? Thanks.
        No I was just saying to try focusing the ChartControl instead as a test however if that did not work, I would not be certain of a solution here. In general, there is nothing specific suggested for handling keyboard input in the platform as there are many existing keyboard events and hotkeys already active. You can explore using the preview key events, however, that still falls within C# requirements of having the control-focused for those events to be triggered.


        Please let me know if I may be of further assistance.

        JesseNinjaTrader Customer Service

        Comment


          #5
          possible workaround Solution

          Comment

          Latest Posts

          Collapse

          Topics Statistics Last Post
          Started by elirion, Today, 01:36 AM
          0 responses
          3 views
          0 likes
          Last Post elirion
          by elirion
           
          Started by gentlebenthebear, Today, 01:30 AM
          0 responses
          4 views
          0 likes
          Last Post gentlebenthebear  
          Started by samish18, Yesterday, 08:31 AM
          2 responses
          9 views
          0 likes
          Last Post elirion
          by elirion
           
          Started by Mestor, 03-10-2023, 01:50 AM
          16 responses
          390 views
          0 likes
          Last Post z.franck  
          Started by rtwave, 04-12-2024, 09:30 AM
          4 responses
          34 views
          0 likes
          Last Post rtwave
          by rtwave
           
          Working...
          X