RPA.Desktop.Press keys multiple times

Hi there,

I’m trying to refactor the following:
RPA.Desktop.Press Keys tab tab tab tab tab
in something more readable, like:
RPA.Desktop.Press Keys tab{5}

But it doesn’t seem to accept it.

Is it possible to refactor this?
What would be the syntax?

Best regards,

Misread the library name, ignore, sorry.

You could create a simple custom keyword that takes in the key and the times to repeat?


Below comment is helpful for the Windows library only

Side comment: We strongly suggest using Send Keys from the new RPA.Windows as of rpaframework==13.0.0.

Then you can replace the repetition with something like:

${keys} =    Evaluate    '{TAB}'*${5}
Windows.Send Keys    keys=${keys}

I forgot to mention, I’m running Linux not Windows :yum:

1 Like

Still, refactoring it with ${keys} = Evaluate '{tab}'*${5}, then sending these ${keys} might work.
And you can put this line into a keyword as Jani recommended, which accepts an integer parameter that instructs the evaluation on how many times to repeat your key.

Will this work for you?

Thanks for the advice. :+1:
So I come up with this, if that can help others:

Press Keys Multiple
    [Arguments]  ${key}
        ...      ${times}

    FOR  ${i}  IN RANGE  ${times}
        RPA.Desktop.Press Keys  ${Key}

Press tab
   Press Keys Multiple    tab    3

Well there is already builtin keyword Repeat Keyword

Press Key X Times
     [Arguments]   ${key}   ${times}
     Repeat Keyword   ${times} times   RPA.Desktop.Press Keys  ${key}

That’s an idea.
But I think Jani’s way scales better, mainly if you have different keys to send a different number of times.

Even better. Thanks :smiley:

1 Like