Search code examples
c#xamlinputwindows-runtimekeypress

How to programmatically trigger key press events in WinRT/C#/XAML?


Today's mission was to enable a WinRT app to be remotely controlled. With all the wiring in place, it was time to implement the remote control actions. The simplest implementation for those actions was to simply simulate a key press inside the process.

Unfortunately, I was unable to find a way to do that. I'm sure it's staring me in the face, but every solution I found online was either via PInvoke, Windows Forms or dialects of WPF that aren't available in WinRT.

Anyone know the magic incantation?

Thanks.


Solution

  • It is not allowed to programmatically trigger a user-initiated event in WinRT XAML. The reason is, some API is restricted to be called only by user interaction. Programmatically causing such events would bypass this security mechanism.