This example shows how to simulate keyboard and mouse input in a web page from C# code. It contains two WPF applications that do the same thing, one with DotNetBrowser and one with CefSharp, so that you can compare the code. Each application loads a bucket list page, types a task into the text field, and clicks the Add button.
The tutorial is available on the DotNetBrowser blog.
- .NET 8 SDK
- A DotNetBrowser license key
- Visual C++ Redistributable 2022 (x64), required by CefSharp
shared/bucket-list.htmlis the page both applications load. Its Add button is enabled only byinputevents.DotNetBrowserApp/MainWindow.xaml.csraises keyboard events onIBrowser.Keyboardand clicks the button withIMouse.SimulateClick().CefSharpApp/MainWindow.xaml.cssends key and mouse events throughIBrowserHostand gets the button position with JavaScript.
Put your license key into the dotnetbrowser.license file in the root
directory of this repository. The build copies it to the output directories of
both applications.
From this directory:
dotnet run --project DotNetBrowserApp
dotnet run --project CefSharpAppOr open InputSimulation.sln in your IDE and run either project.
In the window, click Type task, then Click Add. The task appears in the list.