mwcraig / ipyevents

A custom widget for returning mouse and keyboard events to Python. Documentation:
https://ipyevents.readthedocs.io/en/latest/index.html
BSD 3-Clause "New" or "Revised" License
112 stars 27 forks source link

Optionally passing some events to browser #77

Open asaboor-gh opened 1 year ago

asaboor-gh commented 1 year ago

Is there are way we can propagate a keydown event to browser to do default action? For example, with Ctrl + P we can print page, but it doesn't work with ipyevents as expected.

Related to this is another option of dispatching a new event when a key is pressed, e.g. let say I press key Ctrl + P and it does not propagate to notebook/browser that is fine, but what if I can handle that by adding something like:

def handle_keydown(event):
    if event["ctrlKey"] and event["code"] == "p":
        ipyevents.propagate() # This is less flexible, 
        # OR
        ipyevents.dispatch_javascript_event("window.print();") # if such function exists, it is much more flexible      

This second way to dispatch events selectively looks better than just passing events to browser. I am looking specifically for window.dispatchEvent(new Event('resize')); on press of some key or some layout change of widgets.