Incorrect behavior of pressKeyCode on Kepler Appium

Hi VegaTeam,

When running automated tests using Appium 2.2.2 and trying to move the cursor with pressKeyCode, the cursor moves continuously even though I only call it once. It looks like it’s a long press.

 await driver.pressKeyCode(108); // Down
 await driver.pause(1000);

I checked with the vega-video-sample-main app and it’s the same.
Please tell me how to fix this problem. Thank you!
Below is the environment information.
Vega SDK : 0.21.4726
Appium version : 2.2.2
Appium driver : 3.30.0

Hi @VU_VAN_TOAN

Thanks for writing. We are looking into this with our internal teams and will update you with a response ASAP.

Warm regards,
Ivy

1 Like

Hello @VU_VAN_TOAN
Are you using FireTV stick or using simulator?

Do you have the log of appium?

Hello @VU_VAN_TOAN
I have done some test and code checking.

I can reproduce the issue.

and the problem may due to the default key press time is too long.

I will make the change, and the fix shall be available in the next release.

1 Like

You may use the dpad navigation method

to inject a keycode with duration this moment as a workaround

Hi @VU_VAN_TOAN,

Thank you for your patience while we investigated this issue.

We were able to reproduce and resolve the problem you reported with pressKeyCode on Kepler Appium. The issue was caused by the default key press duration being set to 1 second in the AppiumKeplerDriver code, which is too long and causes the continuous scrolling behavior you observed.

Solution:

We’ve identified the necessary code changes to fix this issue. I’ve attached a test file test_appium_issue.py (1.0 KB) that demonstrates the corrected implementation with the adjusted key press duration.

Please review the attached file and let us know if this resolves your issue or if you need any further assistance.

Warm regards,
Aishwarya

1 Like

Thanks for your feedback.
I am writing the script in javascript so can you send me the javascript script?
Looking forward to hearing from you soon!

Hello @VU_VAN_TOAN
You may use this example code, and modify it.

import { Browser } from ‘webdriverio’;
import { AppiumConfig } from ‘../config/Capabilities’;

export class KeyboardActions {
private static readonly ENTER = 28;
private static readonly BACK = 158;
private static readonly UP = 103;
private static readonly DOWN = 108;
private static readonly LEFT = 105;
private static readonly RIGHT = 106;
private static readonly PLAY = 164;

constructor(private driver: Browser) {}

private async pressKey(keyCode: number): Promise {
try {
await this.driver.execute(‘jsonrpc: injectInputKeyEvent’, [
{
inputKeyEvent: keyCode.toString(),
holdDuration: AppiumConfig.KEYBOARD_WAIT_TIME,
},
]);
} catch (error) {
throw new Error(‘Not able to press keys’);
}
}

async pressEnter(): Promise {
await this.pressKey(KeyboardActions.ENTER);
}

async pressBack(): Promise {
await this.pressKey(KeyboardActions.BACK);
}

async pressUp(): Promise {
await this.pressKey(KeyboardActions.UP);
}

async pressDown(): Promise {
await this.pressKey(KeyboardActions.DOWN);
}

async pressLeft(): Promise {
await this.pressKey(KeyboardActions.LEFT);
}

async pressRight(): Promise {
await this.pressKey(KeyboardActions.RIGHT);
}

async pressPlay(): Promise {
await this.pressKey(KeyboardActions.PLAY);
}

async pressXKeyYTimesAndWaitZ(
pressTimes: number,
direction: string,
waitTime: number
): Promise {
const directionMap: { [key: string]: () => Promise } = {
up: () => this.pressUp(),
down: () => this.pressDown(),
left: () => this.pressLeft(),
right: () => this.pressRight(),
enter: () => this.pressEnter(),
back: () => this.pressBack(),
play: () => this.pressPlay(),
};

const action = directionMap[direction.toLowerCase()];
if (action) {
  for (let i = 0; i < pressTimes; i++) {
    await action();
    await this.driver.pause(waitTime);
  }
} else {
  throw new Error(
    `Invalid direction: ${direction}. Valid options: ${Object.keys(directionMap)}`
  );
}

}
}
1 Like

Thank you for your feedback. I tried it and it worked. Until there is an official fix, I will use this method.

1 Like

Hi @VU_VAN_TOAN,

For the JavaScript reference (https://developer.amazon.com/docs/vega/0.21/appium-write-tests.html), the default hold duration of 1 second causes unintended long-press behavior. Use a custom 100ms duration instead:

// Test keycode with custom duration (100ms)
driver.execute_script(
  "jsonrpc: injectInputKeyEvent",
  [{ inputKeyEvent: "108", holdDuration: 100 }]
);

This resolves the continuous cursor movement issue. A permanent fix is planned for the next release.

Let me know if this works for you.

Warm regards,
Aishwarya

1 Like