Skip to content

gf.keyPress

gf.keyPress(key: string|number, options?: Object, count?: number): Promise<void>

Section titled “gf.keyPress(key: string|number, options?: Object, count?: number): Promise<void>”

Simulates a key press event on the document.

  • key: The key to be pressed. Either a key code as number or string.
    • You can use the gf.KEYS object to specify the key argument.
  • options.altKey: Indicates if the Alt key is pressed.
  • options.ctrlKey: Indicates if the Ctrl key is pressed.
  • options.metaKey: Indicates if the Meta key is pressed.
  • options.shiftKey: Indicates if the Shift key is pressed.
  • count: (Default = 0) The number of times to repeat the key press sequence.
  • Returns a promise that resolves when the key press is complete.
describe('Test script', function () {
it('Test 1', async () => {
await gf.keyPress('a'); // Will press key - 'a'
await gf.keyPress('a', void 0, 2); // Will press key - 'a' two times
await gf.keyPress('a', { altKey: true }, 2); // Will press key - 'a' with alt pressed key two times
await gf.keyPress(gf.KEYS.TAB, void 0, 2); // Will press the Tab key two times
});
});