1

This is my code snippet,

reg = selectRegion("Selected a region")
reg.keyDown(KEY_CTRL)
reg.keyUp()

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??

Nathaniel Waisbrot
  • 23,261
  • 7
  • 71
  • 99
Praveen kumar
  • 597
  • 2
  • 14
  • 26

1 Answers1

2

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:

reg.keyDown(CTRL)
... some code that scrolls ...
reg.keyUp(CTRL)

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.)

Nathaniel Waisbrot
  • 23,261
  • 7
  • 71
  • 99