Announcement
Collapse
No announcement yet.
Partner 728x90
Collapse
NinjaTrader
OnKeyDown does not fire coming from lost focus window
Collapse
X
-
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?Tags: None
-
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.
-
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
-
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.
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.Are you referring to using a global key hook? Do you have any examples available? Thanks.
Please let me know if I may be of further assistance.
Comment
Latest Posts
Collapse
| Topics | Statistics | Last Post | ||
|---|---|---|---|---|
|
Started by Geovanny Suaza, 02-11-2026, 06:32 PM
|
0 responses
647 views
0 likes
|
Last Post
|
||
|
Started by Geovanny Suaza, 02-11-2026, 05:51 PM
|
0 responses
369 views
1 like
|
Last Post
|
||
|
Started by Mindset, 02-09-2026, 11:44 AM
|
0 responses
108 views
0 likes
|
Last Post
by Mindset
02-09-2026, 11:44 AM
|
||
|
Started by Geovanny Suaza, 02-02-2026, 12:30 PM
|
0 responses
572 views
1 like
|
Last Post
|
||
|
Started by RFrosty, 01-28-2026, 06:49 PM
|
0 responses
573 views
1 like
|
Last Post
by RFrosty
01-28-2026, 06:49 PM
|

Comment