How to use keyDown() and keyUp() in sikuli


This is my code snippet,

reg = selectRegion("Selected a region")

My objective is to select some lines, as we do it by pressing CTRL and then scrolling down, but it throws

java.lang.IllegalArgumentException: java.lang.IllegalArgumentException: Invalid key code

It's obvious that I have done something wrong, Could any one help me out with this??

Best Solution

The documentation on special keys says to use CTRL with keyDown(). KEY_CTRL is used with type() or other cases where you want to add the modifier key as a mask. (And that's actually deprecated and should be KeyModifier.CTRL now, instead.)

For example:

... some code that scrolls ...

Or to press the "down" key twice while holding control:

reg.type(Key.DOWN + Key.DOWN, KeyModifier.CTRL);

(As a side-note, it's generally shift that's used as the modifier key for creating a selection and not control.)

Related Question