Shortcut Input control available?

Is the shortcut input control available does anyone know? the one that allows the user to enter a key press to define a shortcut that you find in settings.

1 Like

Search for ‘hotkeys ninjatrader’ on Google and it’ll take you to the Ninjatrader documentation.

There’s no documentation on the code required for the HotKey input control. There is an example file out there called ‘InputPropertyEditorsExample’ which demo’s various types of input controls…file picker, collection, trading hours etc etc…almost everything you can think of except the hotkey input

Here it is: https://ninjatrader.com/support/helpguides/nt8/NT%20HelpGuide%20English.html?hot_key_manager.htm

Unless I’m missing something this just explains how to use the hot key settings. I’m talking about code for the input control to allow the user to record a key press. A control like …

	[NinjaScriptProperty]
	[Display(Name = "Sound File Picker", GroupName = "File Pickers")]
	[PropertyEditor("NinjaTrader.Gui.Tools.FilePathPicker", Filter = "Wav Files (*.wav)|*.wav", Title = "Select Files")]
	public string MyWavSoundFilePath
	{ get; set; }

	[NinjaScriptProperty]
	[Display(Name = "Any File Picker", GroupName = "File Pickers")]
	[PropertyEditor("NinjaTrader.Gui.Tools.FilePathPicker", Filter = "Any Files (*.*)|*.*", Title = "Select Files")]
	public string MyGenericFilePath
	{ get; set; }

	// TODO: Add a custom dialog window editor. note that it uses the same setup as CustomWPFWindowDialogEditor
	#endregion

	#region HyperLink Properties
	[Display(Name = "Hyperlink", GroupName = "HyperLinks")]
	[PropertyEditor("NinjaTrader.NinjaScript.Indicators.PropertyGridControlsExamples.HyperLinkEditor")]
	public string HyperLinkProperty { get; set; }
	#endregion

	#region String Properties	
	[Display(Name = "Single Line Text", GroupName = "Strings", Order = 1)]
	public string DisplayTextSingleLine
	{ get; set; }
	
	[Display(Name = "Multi Line Text", GroupName = "Strings", Order = 2)]
	[PropertyEditor("NinjaTrader.Gui.Tools.MultilineEditor")]
	public string DisplayTextMultiLine
	{ get; set; }

Programmatically, with csharp/ninjascript? I wouldn’t know.

Perhaps another member of the community will chime in.

I was curious about the exact same thing 2 days back, I have hardcoded a shortcut key like Ctrl+H to show hide my indicator window, would love to have it as a configurable parameter in the Indicator setting.
Please let us know if you find a solution.

WPF does not have a control to allow user selectable keys for keypress events. The typical thing to do here is use a TextBox in preview mode. You can find various implementations on Github if you search “WPF HotKeyTextBox” or you can try this.

using System.Windows;
using System.Windows.Controls;
using System.Windows.Input;

public class HotKeyBox : TextBox
{
    public static readonly DependencyProperty HotKeyProperty =
        DependencyProperty.Register(nameof(HotKey), typeof(Key), typeof(HotKeyBox),
            new FrameworkPropertyMetadata(Key.None, OnHotKeyChanged));

    public static readonly DependencyProperty ModifierKeysProperty =
        DependencyProperty.Register(nameof(ModifierKeys), typeof(ModifierKeys), typeof(HotKeyBox),
            new FrameworkPropertyMetadata(ModifierKeys.None, OnHotKeyChanged));

    public Key HotKey
    {
        get => (Key)GetValue(HotKeyProperty);
        set => SetValue(HotKeyProperty, value);
    }

    public ModifierKeys ModifierKeys
    {
        get => (ModifierKeys)GetValue(ModifierKeysProperty);
        set => SetValue(ModifierKeysProperty, value);
    }

    public HotKeyBox()
    {
        IsReadOnly = true;           // ← very important
        IsReadOnlyCaretVisible = false;
        AllowDrop = false;
        Focusable = true;
    }

    protected override void OnPreviewKeyDown(KeyEventArgs e)
    {
        // Eat almost everything
        e.Handled = true;

        // Let user clear with Backspace / Delete
        if (e.Key == Key.Back || e.Key == Key.Delete)
        {
            HotKey = Key.None;
            ModifierKeys = ModifierKeys.None;
            return;
        }

        // We usually want modifiers + normal key
        var modifiers = Keyboard.Modifiers & (ModifierKeys.Control | ModifierKeys.Alt | ModifierKeys.Shift | ModifierKeys.Windows);

        // Ignore modifier keys themselves + some special keys
        if (IsModifierKey(e.Key) || e.Key == Key.System || e.Key == Key.ImeProcessed)
            return;

        // Accept the combination
        HotKey = e.Key;
        ModifierKeys = modifiers;

        // Optional: you can focus next control after picking
        // MoveFocus(new TraversalRequest(FocusNavigationDirection.Next));
    }

    private static bool IsModifierKey(Key key) =>
        key is Key.LeftCtrl or Key.RightCtrl or
               Key.LeftAlt or Key.RightAlt or
               Key.LeftShift or Key.RightShift or
               Key.LWin or Key.RWin;

    private static void OnHotKeyChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
    {
        if (d is HotKeyBox box)
            box.Text = GetFriendlyHotkeyString(box.ModifierKeys, box.HotKey);
    }

    public static string GetFriendlyHotkeyString(ModifierKeys modifiers, Key key)
    {
        if (key == Key.None) return "";

        string s = "";

        if ((modifiers & ModifierKeys.Control) != 0) s += "Ctrl+";
        if ((modifiers & ModifierKeys.Alt)     != 0) s += "Alt+";
        if ((modifiers & ModifierKeys.Shift)   != 0) s += "Shift+";
        if ((modifiers & ModifierKeys.Windows) != 0) s += "Win+";

        // Nice display names for some special keys
        s += key switch
        {
            Key.Return   => "Enter",
            Key.Escape   => "Esc",
            Key.Capital  => "Caps Lock",
            Key.NumLock  => "Num Lock",
            _            => key.ToString()
        };

        return s;
    }
}
1 Like

I found these:

NinjaTrader.Gui.Tools.KeyGestureStringConverter
NinjaTrader.Gui.Tools.HotKeyInputGestureConverter

but they just appear as a text field