Question: Bind key-press (hotkey) to activate widget event
Hello, I have a question. Let's say I create a simple widget in Jupyter, like the button from the documentation.
from IPython.display import display
button = widgets.Button(description="Click Me!")
display(button)
def on_button_clicked(b):
print("Button clicked.")
button.on_click(on_button_clicked)
Now, I want this button to activate whenever I press a certain hotkey on the keyboard, let's say one of the arrow keys. Is there any possibility of doing this? If not, are there any alternative approaches? Packages or documentation I have missed?
Best regards, Bjørn
The only jupyter widget I know of that has been used to assign arbitrary hotkeys from the user is the https://github.com/mwcraig/ipyevents project.
ipyevents looks great, but unfortunately has this limitation: "The keyboard events are triggered only if the mouse is over the widget."
Is there another work around this issue? It would be great to have a hotkey option to trigger callbacks when defining on_click, observe, etc...
Its been several years, just wondering if this was ever worked out?
I wonder if it makes sense to make https://github.com/fgr-araujo/vue-shortkey available as a ipywidget (cc @mariobuikhuizen )
That wouldn't make it work with ipywidgets controls (the widgets that ipywidgets ships), but it could work with ipyvuetify.
This would be very useful, in particular for https://github.com/voila-dashboards/voila.
E.g., one might want to bind Ctrl+Enter to "execute" (I am aware that this hotkey is usually used by Jupyter).
As a workaround, I have been experimenting with display(HTML()) to inject custom JavaScript.