# Appium WinAppDriver .PressKeyCode Enums for Keys

**URL:** <https://discuss.appium.io/t/appium-winappdriver-presskeycode-enums-for-keys/38771>\
**Category:** Support\
**Created:** [March 22, 2023, 9:10pm UTC](https://discuss.appium.io/t/appium-winappdriver-presskeycode-enums-for-keys/38771 "2023-03-22T21:10:59Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![TonyH](https://discuss.appium.io/user_avatar/discuss.appium.io/tonyh/32/11211_2.png) [@TonyH](https://discuss.appium.io/u/TonyH)\
**Post date:** [March 22, 2023, 9:10pm UTC](https://discuss.appium.io/t/appium-winappdriver-presskeycode-enums-for-keys/38771/1 "2023-03-22T21:10:59Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![wreed](https://discuss.appium.io/letter_avatar_proxy/v4/letter/w/919ad9/32.png) [@wreed](https://discuss.appium.io/u/wreed)\
**Post date:** [March 22, 2023, 9:45pm UTC](https://discuss.appium.io/t/appium-winappdriver-presskeycode-enums-for-keys/38771/2 "2023-03-22T21:45:30Z")

</div>

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

> **[UI testing for Windows apps with WinAppDriver and Appium](https://techcommunity.microsoft.com/t5/modern-work-app-consult-blog/ui-testing-for-windows-apps-with-winappdriver-and-appium/ba-p/825352)**
>
> In another post on this blog we have seen how telemetry is important to implement a good DevOps story for your software projects. Another important piece of the puzzle is testing. In order to be agile and deliver fast, we need to make sure...

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

> <https://github.com/microsoft/WinAppDriver/blob/master/Tests/WebDriverAPI/SendKeys.cs>

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

```
[TestMethod]
        public void SendKeys_NonPrintableKeys()
        {
            session.Keyboard.SendKeys("9");
            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);
        }
```

---

<div class="post-metadata">

**Author:** ![TonyH](https://discuss.appium.io/user_avatar/discuss.appium.io/tonyh/32/11211_2.png) [@TonyH](https://discuss.appium.io/u/TonyH)\
**Post date:** [March 24, 2023, 10:49am UTC](https://discuss.appium.io/t/appium-winappdriver-presskeycode-enums-for-keys/38771/3 "2023-03-24T10:49:53Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![TonyH](https://discuss.appium.io/user_avatar/discuss.appium.io/tonyh/32/11211_2.png) [@TonyH](https://discuss.appium.io/u/TonyH)\
**Post date:** [March 27, 2023, 5:04pm UTC](https://discuss.appium.io/t/appium-winappdriver-presskeycode-enums-for-keys/38771/4 "2023-03-27T17:04:37Z")

</div>

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!).

---

<div class="post-metadata">

**Author:** ![wreed](https://discuss.appium.io/letter_avatar_proxy/v4/letter/w/919ad9/32.png) [@wreed](https://discuss.appium.io/u/wreed)\
**Post date:** [March 27, 2023, 5:38pm UTC](https://discuss.appium.io/t/appium-winappdriver-presskeycode-enums-for-keys/38771/5 "2023-03-27T17:38:52Z")

</div>

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.
