Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Documentation: Keyboard Events #583

Open
imgurbot12 opened this issue Dec 9, 2023 · 2 comments
Open

Documentation: Keyboard Events #583

imgurbot12 opened this issue Dec 9, 2023 · 2 comments

Comments

@imgurbot12
Copy link

I've looked around for a while and have yet to find any existing documentation on how to implement keyboard/keypress events when building a gui with relm4. I tried a general search-engine, relm4's docs.rs, and the book published on relm4.org but they don't even include a reference to keyboard events.

I found some details on how to work with them directly in gtk4-rs from stackoverflow but I'm not sure how to integrate them into relm successfully so far.

I can see there was some discussion about implementation in the past (#548) but with little commentary. Would it possible to include a tutorial or basic description on how to implement them please?

Relm4 looks very promising for a project I'm working on at the moment but keyboard events are absolutely essential meaning all my effort will be for nil if I can't find a solution lol. Any help would be appreciated thanks!

@AaronErhardt
Copy link
Member

You're right, this topic is definitely lacking in our docs.

Depending on what you want to implement there are two mechanisms you can use:

  1. If you want to add shortcuts to your app, you need to create and register so called "actions", which are basically callbacks that can be triggered by widgets or keyboard presses. After setting up and action, you can use set_accelerators_for_action to setup a keyboard shortcut that triggers the action: https://github.com/Relm4/Relm4/blob/main/examples/actions.rs#L68
  2. If you want to get events for all key presses, you can add a EventControllerKey to a widget with add_controller. By connecting to the controllers key-pressed event, you should get an event for each key-press as long as the widget is in focus (I think if you use the main window, you should basically get all inputs).

@imgurbot12
Copy link
Author

@AaronErhardt, this is exactly what I'm looking for thank you! I can certainly get started on what I'm working on with this, so that's all I need.

I'm going to leave the issue open in case its of any use for a project tracker or anything but if you'd prefer to resolve it then feel free to close. Appreciate the response :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants