flow icon indicating copy to clipboard operation
flow copied to clipboard

Can't listen for colon

Open mhus opened this issue 3 months ago • 1 comments

Description of the bug

Listen on grid to press colon did not work there is no Key.COLON and even key.of(":") will not work.

Expected behavior

Get a event on pressing ":"

Minimal reproducible example

ui().addShortcutListener((event) -> doSomething() , Key.of(":")).listenOn(component);

Versions

  • Vaadin / Flow version: 24.3.9
  • Java version: 21.0.2
  • OS version: Macos
  • Browser version (if applicable): Chrome
  • Application Server (if applicable):
  • IDE (if applicable):

mhus avatar May 09 '24 21:05 mhus

Colon is not listed in the keycode values (https://developer.mozilla.org/en-US/docs/Web/API/UI_Events/Keyboard_event_code_values). So, this is probably the reason why there's no enumeration entry.

I think the problem here is that the colon key is often shared with another key, and you have to press also a modifier (for example SHIFT). On my keyboard layout, I have colon and period sharing the same button; to output a colon, I have to press SHIFT.

So, back to your code, I can make it work by activating also SHIFT on the shortcut, for example

ui().addShortcutListener((event) -> doSomething() , Key.of(":"))
   .withShift()
   .listenOn(component);

This looks like a workaround, but I currently don't know if we can do something on Flow to better handle these special cases.

mcollovati avatar May 10 '24 06:05 mcollovati