contexts icon indicating copy to clipboard operation
contexts copied to clipboard

add press key feature

Open gimler opened this issue 8 years ago • 5 comments

It make it possible to press a specific keyboard key.

(I )press key :char
(I )press key :char on :element

example:

Then I press key "r"
Then I press key "["
Then I press key "ctrl+r"

gimler avatar Jul 06 '16 12:07 gimler

ready to merge

gimler avatar Jul 07 '16 06:07 gimler

👍

stevenkroiher avatar Jul 07 '16 09:07 stevenkroiher

Good work, I have just one point: the key and modifier arguments need more abstration.

Something like that:

Then I press key "a"
Then I press key "<enter>"
Then I press key "Ctrl+A"

sanpii avatar Jul 07 '16 14:07 sanpii

<enter> is a liddle bit tricky we can have a function convertSpecialKeyToChar($key) and a convert array for all keys but i think this is not sexy. Do you have another idea?

gimler avatar Jul 11 '16 07:07 gimler

Do you have another idea?

No, this is what I think, but simpler than a regex:

function convertKey($char)
{
    static $specialKeys = [
        '<enter>' => 13,
    ];

    list($modifier, $key) = explode('+', $char, 2);

    if (isset($specialKeys[$key])) {
        $key = $specialKeys[$key];
    }

    return [$modifier, $key];
}

Not tested and I don’t know if multiple modifiers are supported by mink.

sanpii avatar Jul 11 '16 09:07 sanpii