Blazor hybrid keyboard events on Windows

John 21 Reputation points
2022-11-28T19:49:56.467+00:00

Hi,

I'm developing a desktop application using Blazor hybrid and C#, .NET 7. I'd like to listen for hotkeys/shortcuts. E.g., F1. How should this be done ?

(I can't find anything in the documentation. Obviously, I know how it could be done using js but is there a way by just using Blazor ... ?)

Many thanks

Developer technologies | .NET | Blazor
0 comments No comments
{count} votes

Accepted answer
  1. Bruce (SqlWork.com) 78,161 Reputation points Volunteer Moderator
    2022-11-28T23:34:47.807+00:00

    the Hybrid app is running in a webview. so it standard browser keyboard handling, via the keyboard events (as as js).

    [index.razor]  
      
    @page "/"  
      
    <input type="text" @onkeydown="KeyboardEventHandler " @onkeypress=" KeyboardEventHandler " @onkeyup="KeyboardEventHandler "/>  
      
    <h4>@KeyPressed </h4>  
    <h4>@EventInfo</h4>  
      
    @code {  
        string KeyPressed = "";  
        string EventInfo = "";  
        private void KeyboardEventHandler(KeyboardEventArgs args)  
        {  
            KeyPressed = "Key Pressed is " + args.Key;  
            EventInfo = "Event Type " + args.Type;  
        }  
    }  
    
    1 person found this answer helpful.
    0 comments No comments

0 additional answers

Sort by: Most helpful

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.