Gael
April 4, 2022, 7:21am
#1
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,
Gael.
jani
April 4, 2022, 8:19am
#2
Misread the library name, ignore, sorry.
You could create a simple custom keyword that takes in the key and the times to repeat?
2 Likes
cosmin
April 4, 2022, 8:38am
#3
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}
Gael
April 4, 2022, 8:46am
#4
I forgot to mention, I’m running Linux not Windows
1 Like
cosmin
April 4, 2022, 8:50am
#5
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?
Gael
April 4, 2022, 9:02am
#6
Thanks for the advice.
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}
END
Press tab
Press Keys Multiple tab 3
mika
April 4, 2022, 9:06am
#7
Well there is already builtin keyword Repeat Keyword
Press Key X Times
[Arguments] ${key} ${times}
Repeat Keyword ${times} times RPA.Desktop.Press Keys ${key}
2 Likes
Gael
April 4, 2022, 9:07am
#8
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.