Replies: 2 comments 4 replies
-
You can only send key events to the specific avalonia control/window using |
Beta Was this translation helpful? Give feedback.
-
@maxkatz6 , The technique you suggested may solve a problem I'm working on. I want to programmatically focus a I have not been able to get it to work though. public MainWindow() {
InitializeComponent();
Dispatcher.UIThread.Post(() => {
RaiseEvent(new KeyEventArgs {
Key = Key.Tab,
RoutedEvent = new RoutedEvent(nameof(KeyDownEvent), RoutingStrategies.Bubble,
typeof(KeyEventArgs), typeof(Window))
});
});
} But that has no effect. Neither does this: public MainWindow() {
InitializeComponent();
Dispatcher.UIThread.Post(() => {
OnKeyDown(new KeyEventArgs {Key = Key.Tab});
});
} I would appreciate any suggestions. |
Beta Was this translation helpful? Give feedback.
-
Hello all,
I am looking for a way to simulate writing on a keyboard in my application. I tried to use the Nuget package Desktop.Robot for this (https://github.com/lucassklp/Desktop.Robot). Unfortunately this only works on Windows and on macos the application crashes. I have already opened an issue on Github describing the problem under macos (lucassklp/Desktop.Robot#36).
With Windows.Forms the keyboard simulation works with the help of the SendKeys method (https://learn.microsoft.com/de-de/dotnet/api/system.windows.forms.sendkeys.send?view=windowsdesktop-7.0)
I would now like to implement this approach for Windows and Macos in Avalonia.
Does anyone of you have an idea how to simulate such a keyboard input programmatically in Avalonia? I am grateful for any tip :)
Beta Was this translation helpful? Give feedback.
All reactions