# How to handle native android keyboard using appium

**URL:** <https://discuss.appium.io/t/how-to-handle-native-android-keyboard-using-appium/1764>\
**Category:** Issues/Bugs\
**Created:** [December 2, 2014, 6:34am UTC](https://discuss.appium.io/t/how-to-handle-native-android-keyboard-using-appium/1764 "2014-12-02T06:34:41Z")\
**Posts on this page:** 20\
**Page:** 2

<div class="post-metadata">

**Author:** ![UD](https://discuss.appium.io/letter_avatar_proxy/v4/letter/u/3be4f8/32.png) [@UD](https://discuss.appium.io/u/UD)\
**Post date:** [February 18, 2016, 11:02am UTC](https://discuss.appium.io/t/how-to-handle-native-android-keyboard-using-appium/1764/21 "2016-02-18T11:02:12Z")

</div>

Except what rakesh said in the above thread(as i cannot force developer to write extra code and developers are not accessible for me)

I tried all the ways specified in this thread, but didnt help. Can someone help me here?

**element.sendKeys(strValue+"\n");** - entering the value but soon after navigating to home screen.

**element.sendKeys(strValue);**  
**String command = “adb -s input keyevent KEYCODE\_SEARCH”;**  
\*\* try {\*\*  
\*\* Process result = Runtime.getRuntime().exec(command);\*\*  
\*\* } catch (IOException e) {\*\*  
\*\* // TODO Auto-generated catch block\*\*  
\*\* e.printStackTrace();\*\*  
\*\* }\*\*  
enter the value but didnt click on Search button.

**element.sendKeys(strValue);**  
**driver.sendKeyEvent(AndroidKeyCode.ENTER);**  
Enter the value and bringing back to home screen.

Also tried with Keyevent codes 84 and 66, but didnt help.

Can someone let me know any other soluctions

---

<div class="post-metadata">

**Author:** ![rakesh](https://discuss.appium.io/user_avatar/discuss.appium.io/rakesh/32/2165_2.png) [@rakesh](https://discuss.appium.io/u/rakesh)\
**Post date:** [February 18, 2016, 11:25am UTC](https://discuss.appium.io/t/how-to-handle-native-android-keyboard-using-appium/1764/22 "2016-02-18T11:25:55Z")

</div>

Hi UD

i tried all solution nothing worked for me… i have wasted lots of time trying to find solution without approaching developers, but i did’t do any progress …

my suggestion is ask you develop to add click Listers then it should work

RK

---

<div class="post-metadata">

**Author:** ![UD](https://discuss.appium.io/letter_avatar_proxy/v4/letter/u/3be4f8/32.png) [@UD](https://discuss.appium.io/u/UD)\
**Post date:** [February 18, 2016, 12:18pm UTC](https://discuss.appium.io/t/how-to-handle-native-android-keyboard-using-appium/1764/23 "2016-02-18T12:18:39Z")

</div>

Ohhhhh… the problem for me is, the app developers are 3rd party vendors and we dont have any access to approach them.

---

<div class="post-metadata">

**Author:** ![rashiatry](https://discuss.appium.io/letter_avatar_proxy/v4/letter/r/a8b319/32.png) [@rashiatry](https://discuss.appium.io/u/rashiatry)\
**Post date:** [May 5, 2016, 7:07am UTC](https://discuss.appium.io/t/how-to-handle-native-android-keyboard-using-appium/1764/24 "2016-05-05T07:07:07Z")

</div>

@UD  
have you been able to get this problem solved?

---

<div class="post-metadata">

**Author:** ![calin-ciobanu](https://discuss.appium.io/user_avatar/discuss.appium.io/calin-ciobanu/32/2164_2.png) [@calin-ciobanu](https://discuss.appium.io/u/calin-ciobanu)\
**Post date:** [May 11, 2016, 9:38am UTC](https://discuss.appium.io/t/how-to-handle-native-android-keyboard-using-appium/1764/25 "2016-05-11T09:38:25Z")

</div>

@UD the only workaround that I found is to use a third party keyboard (GO Keyboard works for me) and then send key event 66. Works as expected. Maybe if you reverse engineer GO Keyboard implementation you can get more insight on how to make it work without a third party keyboard. Cheers!

---

<div class="post-metadata">

**Author:** ![tapanagkumar](https://discuss.appium.io/letter_avatar_proxy/v4/letter/t/7c8e57/32.png) [@tapanagkumar](https://discuss.appium.io/u/tapanagkumar)\
**Post date:** [May 31, 2016, 7:06am UTC](https://discuss.appium.io/t/how-to-handle-native-android-keyboard-using-appium/1764/26 "2016-05-31T07:06:24Z")

</div>

driver.pressKeyCode(66);  
//This is to press “Enter” from keyboard

[https://developer.android.com/reference/android/view/KeyEvent.html#KEYCODE\_TAB](https://developer.android.com/reference/android/view/KeyEvent.html#KEYCODE_TAB)

---

<div class="post-metadata">

**Author:** ![Jayson\_P](https://discuss.appium.io/letter_avatar_proxy/v4/letter/j/ee59a6/32.png) [@Jayson\_P](https://discuss.appium.io/u/Jayson_P)\
**Post date:** [September 9, 2016, 9:21pm UTC](https://discuss.appium.io/t/how-to-handle-native-android-keyboard-using-appium/1764/27 "2016-09-09T21:21:49Z")

</div>

The `driver.pressKeyCode(66);` method doesn’t work for me. The only other solution I have seen is to tap the button based on coordinates. Although it would work it would be awful when trying to support multiple devices.

Has there been any progress on this topic? This feature is fairly critical for the work that I am doing. If anyone has a solution to this it would be greatly appreciated.

---

<div class="post-metadata">

**Author:** ![Amit\_Tallewar](https://discuss.appium.io/user_avatar/discuss.appium.io/amit_tallewar/32/6700_2.png) [@Amit\_Tallewar](https://discuss.appium.io/u/Amit_Tallewar)\
**Post date:** [September 15, 2016, 8:35am UTC](https://discuss.appium.io/t/how-to-handle-native-android-keyboard-using-appium/1764/28 "2016-09-15T08:35:47Z")

</div>

Hello, Did you have added jars of java client jar and android jar?

---

<div class="post-metadata">

**Author:** ![gamal\_amir](https://discuss.appium.io/letter_avatar_proxy/v4/letter/g/779978/32.png) [@gamal\_amir](https://discuss.appium.io/u/gamal_amir)\
**Post date:** [October 11, 2016, 10:40am UTC](https://discuss.appium.io/t/how-to-handle-native-android-keyboard-using-appium/1764/29 "2016-10-11T10:40:14Z")

</div>

guys i want to add that Appium driver now has key press code in its API

---

<div class="post-metadata">

**Author:** ![sanoj27](https://discuss.appium.io/user_avatar/discuss.appium.io/sanoj27/32/1375_2.png) [@sanoj27](https://discuss.appium.io/u/sanoj27)\
**Post date:** [January 25, 2017, 11:10am UTC](https://discuss.appium.io/t/how-to-handle-native-android-keyboard-using-appium/1764/30 "2017-01-25T11:10:43Z")

</div>

How can we handle enter key on custom numeric keyboard in Android?

---

<div class="post-metadata">

**Author:** ![Al\_Imran](https://discuss.appium.io/user_avatar/discuss.appium.io/al_imran/32/3451_2.png) [@Al\_Imran](https://discuss.appium.io/u/Al_Imran)\
**Post date:** [May 8, 2017, 6:59am UTC](https://discuss.appium.io/t/how-to-handle-native-android-keyboard-using-appium/1764/31 "2017-05-08T06:59:32Z")

</div>

You can try it for maven project:  
`((AndroidDriver)driver).pressKeyCode(66);`

---

<div class="post-metadata">

**Author:** ![aray0322](https://discuss.appium.io/letter_avatar_proxy/v4/letter/a/2bfe46/32.png) [@aray0322](https://discuss.appium.io/u/aray0322)\
**Post date:** [August 31, 2017, 8:54am UTC](https://discuss.appium.io/t/how-to-handle-native-android-keyboard-using-appium/1764/32 "2017-08-31T08:54:20Z")

</div>

I am using Python 3.6 + Appium V1.6.5  
Try the following:

Set the following two lines to your desired\_caps.  
desired\_caps[‘unicodeKeyboard’] = True  
desired\_caps[‘resetKeyboard’] = True

Then use keycode 66. it works for me.  
driver.press\_keycode(66)

---

<div class="post-metadata">

**Author:** ![sam69](https://discuss.appium.io/letter_avatar_proxy/v4/letter/s/7ab992/32.png) [@sam69](https://discuss.appium.io/u/sam69)\
**Post date:** [August 25, 2018, 10:09am UTC](https://discuss.appium.io/t/how-to-handle-native-android-keyboard-using-appium/1764/33 "2018-08-25T10:09:06Z")

</div>

I’m using:  
io.appium -\> 6.1.0  
selenium -\> 3.13.0  
guava -\> 24.0-jre

When I use : ((AndroidDriver)driver).pressKeyCode(67);  
I get the following error message with pressKeyCode instruction striked-on : _The method pressKeyCode(int) from the type PressesKey is deprecated_

---

<div class="post-metadata">

**Author:** ![harshitj](https://discuss.appium.io/letter_avatar_proxy/v4/letter/h/ee59a6/32.png) [@harshitj](https://discuss.appium.io/u/harshitj)\
**Post date:** [August 26, 2018, 5:06am UTC](https://discuss.appium.io/t/how-to-handle-native-android-keyboard-using-appium/1764/34 "2018-08-26T05:06:01Z")

</div>

With 6.1.0, use this way to press a particular key :  
((AndroidDriver) driver).pressKey(new KeyEvent(AndroidKey.ENTER));

---

<div class="post-metadata">

**Author:** ![sam69](https://discuss.appium.io/letter_avatar_proxy/v4/letter/s/7ab992/32.png) [@sam69](https://discuss.appium.io/u/sam69)\
**Post date:** [August 27, 2018, 10:16am UTC](https://discuss.appium.io/t/how-to-handle-native-android-keyboard-using-appium/1764/35 "2018-08-27T10:16:47Z")

</div>

@harshitj :

On using ((AndroidDriver) driver).pressKey(new KeyEvent(AndroidKey.ENTER));

1. pressKey gives error:  
The method pressKey(io.appium.java\_client.android.nativekey.KeyEvent) in the type PressesKey is not applicable for the arguments (java.awt.event.KeyEvent)  
2 quick fixes available:  
Change to longPressKey()  
Change to pressKeyCode()

2. (new KeyEvent(AndroidKey.ENTER) gives error: The constructor KeyEvent(AndroidKey) is undefined

3. KeyEvent is striked.

4. On changing pressKey to pressKeyCode, I’m getting error: The method pressKeyCode(int) in the type PressesKey is not applicable for the arguments (KeyEvent)

---

<div class="post-metadata">

**Author:** ![harshitj](https://discuss.appium.io/letter_avatar_proxy/v4/letter/h/ee59a6/32.png) [@harshitj](https://discuss.appium.io/u/harshitj)\
**Post date:** [August 28, 2018, 6:53am UTC](https://discuss.appium.io/t/how-to-handle-native-android-keyboard-using-appium/1764/36 "2018-08-28T06:53:50Z")

</div>

You have included wrong import ‘KeyEvent’.

Remove : **import java.awt.event.KeyEvent;**

Add these import only :  
**import io.appium.java\_client.android.nativekey.KeyEvent** ;  
import io.appium.java\_client.android.nativekey.AndroidKey;

---

<div class="post-metadata">

**Author:** ![Sankar\_G](https://discuss.appium.io/user_avatar/discuss.appium.io/sankar_g/32/7184_2.png) [@Sankar\_G](https://discuss.appium.io/u/Sankar_G)\
**Post date:** [August 29, 2018, 9:13am UTC](https://discuss.appium.io/t/how-to-handle-native-android-keyboard-using-appium/1764/37 "2018-08-29T09:13:11Z")

</div>

Hi,  
I tried with  
AndroidDriver driver;  
driver.pressKeyCode(66);

It worked for me. Hope it helps you for Android Keyboard Events.  
Enter key.  
Constant Value: 66

---

<div class="post-metadata">

**Author:** ![sam69](https://discuss.appium.io/letter_avatar_proxy/v4/letter/s/7ab992/32.png) [@sam69](https://discuss.appium.io/u/sam69)\
**Post date:** [August 30, 2018, 7:59am UTC](https://discuss.appium.io/t/how-to-handle-native-android-keyboard-using-appium/1764/38 "2018-08-30T07:59:30Z")

</div>

@harshitj, @Sankar_G : Thanks for your inputs.  
Presently I have some other business related roadblock, so I’ll update you after some days on what is working.

---

<div class="post-metadata">

**Author:** ![Bakhtiyar\_Mametyarov](https://discuss.appium.io/letter_avatar_proxy/v4/letter/b/90db22/32.png) [@Bakhtiyar\_Mametyarov](https://discuss.appium.io/u/Bakhtiyar_Mametyarov)\
**Post date:** [September 24, 2018, 12:45am UTC](https://discuss.appium.io/t/how-to-handle-native-android-keyboard-using-appium/1764/39 "2018-09-24T00:45:02Z")

</div>

Thanks a lot! It helps me!

---

<div class="post-metadata">

**Author:** ![suresh\_bijjam](https://discuss.appium.io/user_avatar/discuss.appium.io/suresh_bijjam/32/4859_2.png) [@suresh\_bijjam](https://discuss.appium.io/u/suresh_bijjam)\
**Post date:** [October 26, 2018, 11:51am UTC](https://discuss.appium.io/t/how-to-handle-native-android-keyboard-using-appium/1764/40 "2018-10-26T11:51:18Z")

</div>

it worked…, really cool… thanks

[Previous page](https://discuss.appium.io/t/how-to-handle-native-android-keyboard-using-appium/1764.md?page=1)

[Next page](https://discuss.appium.io/t/how-to-handle-native-android-keyboard-using-appium/1764.md?page=3)
