# Keyboard Events

## Hide Keyboard:

Create a reusable function and call when required in test script

{% code title="helper.java" %}
```java
 public static void hideKeyboard() throws Exception {
        try {
            driver.hideKeyboard();
        } catch (Exception e) {
            throw new Exception("Keyboard should auto-trigger but didn't");
        }
    }
```
{% endcode %}

To hide keyboard call above function from `helper.java` class

```
test.java

$ helper.hideKeyboard();
```

## Open Keyboard:

To create a reusable function and call in test script

{% code title="helper.java" %}
```java
  // Android 
  public static void getKeyboard() throws Exception {
        if (driver instanceof AndroidDriver) {
            ((AndroidDriver) driver).pressKeyCode(AndroidKeyCode.KEYCODE_PAGE_UP);
        }
    }
```
{% endcode %}

To open keyboard call above function from `helper.java` reusable class

```
test.java

$ helper.getKeyboard();
```

## Press key Enter:

To create a reusable function and call in test script

{% code title="helper.java" %}
```java
  // Android 
   public static void pressKeyEnter() {
        if (driver instanceof AndroidDriver) {
            ((AndroidDriver) driver).pressKeyCode(AndroidKeyCode.ENTER);
        }
    }
```
{% endcode %}

To press key ENTER call above function from `helper.java` reusable class

```
test.java

$ helper.pressKeyEnter();
```

## Press key UP:

To create a reusable function and call in test script

{% code title="helper.java" %}
```java
  // Android 
   public static void pressKeyUp() {
        if (driver instanceof AndroidDriver) {
            ((AndroidDriver) driver).pressKeyCode(AndroidKeyCode.ACTION_UP);
        }
    }

```
{% endcode %}

To press key ENTER call above function from `helper.java` reusable class

```
test.java

$ helper.pressKeyUp();
```
