-
I'm building an app that should work in a similar way as Intellisense in Visual Studio, but Windows wide. If global hotkey is pressed, I'm using windows hook to intercept input to foreground window and forward it my WPF app. What I'm looking for, is there a way to forward input into WPF textbox (that is not focused) and let it process it? I'm able to manually append characters to the textbox, but I would like a solution that will be processing other events, like "deleting before cursor", "deleting after cursor", "jumping cursor over words when Ctrl+arrow is pressed", etc. Is this textbox logic implemented in WPF or is it handled by underlaying windows thing? Is there a way to directly use that logic? |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 5 replies
-
If you are trying to create any sort of global input experience, you should write an IME, that's what they are designed for; setting global input hooks is generally frown upon. Some helpful links:
Looks like you can also reach out to people internally if you needed help with that. But to answer your question, the window messages are processed by WPF and delivered to the TextBox control through routed events. You can inject input into WPF by calling This will of course route the events as appropriate. If you want to route the directly to a specific control, you can technically raise the WPF events yourself directly on the controls, for example: textBox.RaiseEvent(new KeyEventArgs(Keyboard.PrimaryDevice,
PresentationSource.FromVisual(this), timestamp, Key.C) { RoutedEvent = KeyDownEvent }); Note that WPF does way much work than that, dealing with routing, preview events etc. More importantly, this will not give you any actual input to the Apps are free to do whatever they want with the input events you are intercepting, and they might turn it into input that you will not be aware of. I even know one or two "typing software" which, like you are intending, is using global hooks to turn key presses into different input (e.g. Indic), and I don't think you can guarantee any order in which the global hooks will be installed. To summarize, WPF does all the processing, but in a global input processing pipeline, not in individual TextBoxes. Some of the processing has focus checks. So you either do the processing yourself and deliver it to your TextBox, or, you let WPF do the processing, but then have to somehow steal it and have it delivered where you need. I have some ideas how you could do that (using events on the Why don't you, instead, use UI automation API to get access to the text in the current input elements and use that? |
Beta Was this translation helpful? Give feedback.
If you are trying to create any sort of global input experience, you should write an IME, that's what they are designed for; setting global input hooks is generally frown upon. Some helpful links:
Looks like you can also reach out to people internally if you needed help with that.
But to answer your question, the window messages are processed by WPF and delivered to the TextBox control through routed events.
You can inject input into WPF by calling
InputManager.ProcessInput
. However, for keyboard input, you would need to passSystem.…