search envelope-o feed check
Home Unanswered Active Tags New Question
user comment-o

Use keyboard with daypilot angular

Asked by Anonymous
2 years ago.

Hello,
I want to add a new action with a shortcut, but I can't detect the keyboard action. I added
useEventBoxes: 'Always',
keyboardEnabled: true,

but it dont fonction.

I tried with @HostListener, but for this to work i must first click outside of matrix

@HostListener('document:keydown', ['$event'])
  handleKeyboardEvent(event: KeyboardEvent) {
    console.log('KeyboardEvent keydown', event);
  }

Please help me find a solution

Answer posted by Dan Letecky [DayPilot]
2 years ago.

The Scheduler attaches "keyup" and "keydown" event handlers to the document element if you enable keyboard support using "keyboardEnabled: true". It uses the document object as the event target (you can change this using "keyboardTarget" property).

See also:
https://doc.daypilot.org/scheduler/keyboard/

If it detects an arrow key, it will move the cursor position within the Scheduler and calls preventDefault(). This doesn't prevent the event from bubbling (even for the arrow keys) to the document object.

I've tried to create a blank project using the UI Builder (https://builder.daypilot.org/), with the @HostListener event handler added (from your snippet) and it seems to work fine.

You may want to check the initial focus - if it is on a custom element that swallows the event, it may not bubble to the document properly. I also recommend reviewing other key event handlers in the app.

This question is more than 1 months old and has been closed. Please create a new question if you have anything to add.