Appium WinAppDriver .PressKeyCode Enums for Keys

I want to test my WinForms application by simulating the depression of keys on the keyboard wherever possible.

Can I use the .PressKeyCode method with WinAppDriver and where do I find the KeyEvent Enums for keys such as ‘Alt’, ‘Enter’, ‘Esc’ etc. ??

I’ve tried using Windows.System.Forms.Keys… but the compiler rejects these.

Here’s a pretty good tutorial on WinAppDriver with code examples:

And here are the tests for WinAppDriver that represent keyboard testing:

You can take a look at how they handle ‘unprintable’ keys like this:

        public void SendKeys_NonPrintableKeys()
            session.Keyboard.SendKeys(Keys.Home + "8");
            session.Keyboard.SendKeys(Keys.Home + "7");
            session.Keyboard.SendKeys(Keys.Home + Keys.Tab);
            session.Keyboard.SendKeys(Keys.Home + Keys.Enter);
            session.Keyboard.SendKeys(Keys.Up + Keys.Tab + "78");
            session.Keyboard.SendKeys(Keys.Home + Keys.Enter);
            session.Keyboard.SendKeys(Keys.Up + Keys.Tab + "7");
            Assert.AreEqual("\t7\r\n\t78\r\n\t789", editBox.Text);

Thanks very much. It looks good I’ll try it out.

That does not seem to work.
As far as I can see driver.SendKeys takes a string as a parameter, so the above sequences end up sending “Ho” or “8” to the control.

Is there any way of sending a Delete or Backspace character to a Windows Control using Appium. Perhaps I will have to use the WinAppDriver API and drive WinAppDriver directly.

I’m actually trying to overwrite a RichTextBox, and unlike a TextBox, .SendKeys does not clear the RTB before sending the string, and the .Clear() method appears not to work with RichTextBoxes. (Very frustrating!).

Getting out of my depth here as I don’t use Windows at all, so can’t replicate.

WRT Rich TextBox, sounds like it could be a bug. Have you thought about filing one on the repo to see if this is correct behavior? Might help to reduce the frustration level if you talked to developers directly with an issue.