Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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.

like image 364
mfeingol Avatar asked Mar 22 '26 17:03

mfeingol


1 Answers

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.

like image 156
Jerry Nixon Avatar answered Mar 25 '26 06:03

Jerry Nixon



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!