2

I want to know when the Ctrl key is released in eclipse RAP, I achieved it in RCP. But learnt it behaves differently on RAP. Any suggestions on how to achieve that.

Juseeth
  • 437
  • 1
  • 6
  • 18

1 Answers1

0

IIRC RAP does not send key events if only a modifier key (such as Shift, Ctrl, etc.) is pressed or released. Only for regular keys, events are sent and the event.stateMask can be queried which modifier keys are currently pressed.

Pressing Ctrl+A will send keyPressed and keyReleased where character is A and stateMask is Ctrl.

Pressing Ctrl only will not send an event.

If in doubt, a simple Shell with a KeyListener attached that prints the events to System.out will help you clarify things.

Rüdiger Herrmann
  • 18,905
  • 11
  • 53
  • 72
  • But the problem is the key listeners are not called at the right time. Which listener should I use for this? – Juseeth May 21 '16 at 14:41
  • There is no way in RAP to get notified when only the Ctrl key was pressed. – Rüdiger Herrmann May 21 '16 at 15:05
  • I mean, I can get which key was pressed from stateMask as you mentioned, but will the key listeners grt notfied when a key is pressed? – Juseeth May 21 '16 at 15:20
  • As I said, the key listener will only be notified if a _regular_ key was pressed, with or without a modifier key. If only a modified key like Ctrl was pressed, not event will be sent. – Rüdiger Herrmann May 21 '16 at 15:51
  • My purpose is to select multiple items with a Ctrl click. So, here I never use individual keys with Ctrl. – Juseeth May 21 '16 at 19:14
  • Which widget (List?, Table?, ...?) do you use to select multiple items? – Rüdiger Herrmann May 21 '16 at 22:44
  • I'm using a ListViewer to Ctrl select, after releasing the Ctrl key, my method should be called. – Juseeth May 21 '16 at 22:47
  • If the `List` widget was created with `SWT.MULTI`it should allow to Ctrl+select items. The selection event will notify if items are selected or unselected. Why are you trying to get the modifier state? – Rüdiger Herrmann May 23 '16 at 09:00
  • I want to do immediately after the elements are selected (i.e., after Ctrl key is released). That is the reason I want to do this. – Juseeth May 23 '16 at 12:19
  • Use a `SelectionListener`. Its `widgetSelected` event is sent whenever the selection changes. – Rüdiger Herrmann May 23 '16 at 13:15