Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Key intercept

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

    Key intercept

    Hello,

    I'm trying to intercept key signals from my strategy class.
    I know that a PreviewKeyDown event needs to be handled to intercept a key, but the Strategy class does not have that. What class in NT8 has a PreviewKeyDown event that I can handle, that is executed when a strategy is running and a key on the keyboard is pressed? I'm guessing it would need to be some global class with a GUI or GUI handling.

    V/R,
    --Maxim

    #2
    DieSlower, Maxim, PreviewKeyDown is a C# WPF Event. It is not NinjaScript-specific. If you search the Internet for "C# WPF PreviewKeyDown", that should point you to useful material.

    The basic principle is straightforward: associate the event handling method for PreviewKeyDown that you write with the control you want to monitor.

    Thanks.
    Multi-Dimensional Managed Trading
    jeronymite
    NinjaTrader Ecosystem Vendor - Mizpah Software

    Comment


      #3
      jeronymite Correct, I know it's part of the .net framework like .ToString(), but as I mentioned not all classes have access to it, so the question it which classes that are accessible from a strategy class do, and which can be assigned a handler from a strategy. It depends on NT8 class structure and design, hence the question.

      Comment


        #4
        Hello DieSlower,

        Thank you for your post.

        You can find a sample of using PreviewKey events in a strategy attached below. This strategy will print "keys pressed" to the NinjaScript Output window when CTRL + SHIFT + 2 is pressed.

        As this is not NinjaScript specific you won't find much information about using WPF key events here on the forum or in the help guide. The best bet is to look for WPF samples online for specific concepts like this and then apply them in NinjaTrader.

        I look forward to being of further assistance.
        Attached Files

        Comment


          #5
          Thank you @NinjaTrader_Kate that works!

          Comment

          Latest Posts

          Collapse

          Topics Statistics Last Post
          Started by argusthome, 03-08-2026, 10:06 AM
          0 responses
          69 views
          0 likes
          Last Post argusthome  
          Started by NabilKhattabi, 03-06-2026, 11:18 AM
          0 responses
          42 views
          0 likes
          Last Post NabilKhattabi  
          Started by Deep42, 03-06-2026, 12:28 AM
          0 responses
          24 views
          0 likes
          Last Post Deep42
          by Deep42
           
          Started by TheRealMorford, 03-05-2026, 06:15 PM
          0 responses
          27 views
          0 likes
          Last Post TheRealMorford  
          Started by Mindset, 02-28-2026, 06:16 AM
          0 responses
          54 views
          0 likes
          Last Post Mindset
          by Mindset
           
          Working...
          X