Android pressKey function throwing an error, "java.lang.IllegalStateException: The key code must be set"

After upgrading to Appium Java Client lib to 9.2.1, androidDriver.pressKey() funtion now throws an error, java.lang.IllegalStateException: The key code must be set
Does anyone know how to solve this?
usage:

androidDriver.pressKey(new KeyEvent(AndroidKey.DEL));

Error:

java.lang.IllegalStateException: The key code must be set

	at io.appium.java_client.android.nativekey.KeyEvent.lambda$build$1(KeyEvent.java:86)
	at java.base/java.util.Optional.orElseThrow(Optional.java:403)
	at io.appium.java_client.android.nativekey.KeyEvent.build(KeyEvent.java:86)
	at io.appium.java_client.android.nativekey.PressesKey.pressKey(PressesKey.java:40)

Library:

<groupId>io.appium</groupId>
<artifactId>java-client</artifactId>
<version>9.2.1</version>

It’s a regression bug. Fixed in v9.2.2

1 Like