Sha256: 47fb8d356891355f1c4627a7c3c45aa6b985c5c9ffbb2553545000ca1b2a002b

Contents?: true

Size: 1.48 KB

Versions: 26

Compression:

Stored size: 1.48 KB

Contents

import '../utils/click/isClickableInput.js';
import '../utils/dataTransfer/Clipboard.js';
import '../utils/edit/isEditable.js';
import '../utils/edit/maxLength.js';
import '../utils/keyDef/readNextDescriptor.js';
import '../utils/misc/level.js';
import { wait } from '../utils/misc/wait.js';
import '../options.js';
import { parseKeyDef } from './parseKeyDef.js';

async function keyboard(text) {
    const actions = parseKeyDef(this.config.keyboardMap, text);
    for(let i = 0; i < actions.length; i++){
        await wait(this.config);
        await keyboardAction(this, actions[i]);
    }
}
async function keyboardAction(instance, { keyDef, releasePrevious, releaseSelf, repeat }) {
    const { system } = instance;
    // Release the key automatically if it was pressed before.
    if (system.keyboard.isKeyPressed(keyDef)) {
        await system.keyboard.keyup(instance, keyDef);
    }
    if (!releasePrevious) {
        for(let i = 1; i <= repeat; i++){
            await system.keyboard.keydown(instance, keyDef);
            if (i < repeat) {
                await wait(instance.config);
            }
        }
        // Release the key only on the last iteration on `state.repeatKey`.
        if (releaseSelf) {
            await system.keyboard.keyup(instance, keyDef);
        }
    }
}
async function releaseAllKeys(instance) {
    for (const k of instance.system.keyboard.getPressedKeys()){
        await instance.system.keyboard.keyup(instance, k);
    }
}

export { keyboard, releaseAllKeys };

Version data entries

26 entries across 26 versions & 1 rubygems

Version Path
clapton-0.0.26 lib/clapton/javascripts/node_modules/@testing-library/user-event/dist/esm/keyboard/index.js
clapton-0.0.25 lib/clapton/javascripts/node_modules/@testing-library/user-event/dist/esm/keyboard/index.js
clapton-0.0.24 lib/clapton/javascripts/node_modules/@testing-library/user-event/dist/esm/keyboard/index.js
clapton-0.0.23 lib/clapton/javascripts/node_modules/@testing-library/user-event/dist/esm/keyboard/index.js
clapton-0.0.22 lib/clapton/javascripts/node_modules/@testing-library/user-event/dist/esm/keyboard/index.js
clapton-0.0.21 lib/clapton/javascripts/node_modules/@testing-library/user-event/dist/esm/keyboard/index.js
clapton-0.0.20 lib/clapton/javascripts/node_modules/@testing-library/user-event/dist/esm/keyboard/index.js
clapton-0.0.19 lib/clapton/javascripts/node_modules/@testing-library/user-event/dist/esm/keyboard/index.js
clapton-0.0.18 lib/clapton/javascripts/node_modules/@testing-library/user-event/dist/esm/keyboard/index.js
clapton-0.0.17 lib/clapton/javascripts/node_modules/@testing-library/user-event/dist/esm/keyboard/index.js
clapton-0.0.16 lib/clapton/javascripts/node_modules/@testing-library/user-event/dist/esm/keyboard/index.js
clapton-0.0.15 lib/clapton/javascripts/node_modules/@testing-library/user-event/dist/esm/keyboard/index.js
clapton-0.0.14 lib/clapton/javascripts/node_modules/@testing-library/user-event/dist/esm/keyboard/index.js
clapton-0.0.13 lib/clapton/javascripts/node_modules/@testing-library/user-event/dist/esm/keyboard/index.js
clapton-0.0.12 lib/clapton/javascripts/node_modules/@testing-library/user-event/dist/esm/keyboard/index.js
clapton-0.0.11 lib/clapton/javascripts/node_modules/@testing-library/user-event/dist/esm/keyboard/index.js
clapton-0.0.10 lib/clapton/javascripts/node_modules/@testing-library/user-event/dist/esm/keyboard/index.js
clapton-0.0.9 lib/clapton/javascripts/node_modules/@testing-library/user-event/dist/esm/keyboard/index.js
clapton-0.0.8 lib/clapton/javascripts/node_modules/@testing-library/user-event/dist/esm/keyboard/index.js
clapton-0.0.7 lib/clapton/javascripts/node_modules/@testing-library/user-event/dist/esm/keyboard/index.js