Multiple shortcuts for one action in GTK
Asked Answered
G

2

8

What is the best way to bind multiple keyboard shortcuts to one action in GTK+ 3?

I have been searching for an answer to this for a few days and have come up with naught. The function gtk_accelerator_parse does not support comma-deliminated shortcuts. Putting multiple <accelerator> tags in a .ui file with the same action attribute and different key attributes also does not work.

I do not want to have to write a custom key press handler just so I can have two shortcuts for one action, but is that really the only way?

Granicus answered 16/4, 2012 at 22:32 Comment(0)
A
2

Since GTK version 3.12 (released on 2014-03-25) there is a new method called gtk_application_set_accels_for_action() that should help.

Adroit answered 26/12, 2020 at 12:30 Comment(1)
Thanks! I have not done any GTK programming in years, but this method would have been exactly what I wanted if it had only come out 2 years earlier. :)Granicus
G
1

I have found a way, but it is truly terrible. Using gtk_accel_group_connect I can add additional accelerators for my own functions which can then trigger the action desired based off the key pressed and any modifiers. This however feels like a hack as I am basically creating my own accelerator-to-action map rather than using GTK's.

I would like to know a better way, if anyone knows of one.

Granicus answered 16/4, 2012 at 23:15 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.