jsakamoto / Toolbelt.Blazor.HotKeys2

This is a class library that provides configuration-centric keyboard shortcuts for your Blazor apps.
https://jsakamoto.github.io/Toolbelt.Blazor.HotKeys2/
Mozilla Public License 2.0
87 stars 6 forks source link

Overriding default Browser shortcuts #21

Open phcd30 opened 2 months ago

phcd30 commented 2 months ago

Is there a way to override the browser shortcuts, for example CTRL+S in Edge brings up the Save Dialog instead of the HotKeys configuration I've set up?

jsakamoto commented 2 months ago

Hi @phcd30,

You must be able to override and prevent the default keyboard shortcuts like Ctrl+S without any specials.

However, in some cases, you need to use the HotKeys.CreateContext in the OnAfterRender lifecycle method instead of the OnInitialized lifecycle method. Otherwise, the Blazor HotKeys won't work. My README document said to use the OnInitialized, which might be why you asked such a question. Could you try using the OnAfterRender method instead of the OnInitialized method to initialize the hotkeys?

I have also attached the sample projects that override and prevent the browser's Ctrl+S keyboard shortcut. I hope these sample projects help you.

I also updated the README document to mention the use of the OnAfterRender method to initialize hotkeys.

phcd30 commented 2 months ago

Yes! That seems to work, thanks!