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

Jupyter Lab: Throttling causes keyboard events to continue propagating #60

Open lawruble13 opened 3 years ago

lawruble13 commented 3 years ago

When an event monitor is set up on keyboard events, if it's throttled the event isn't stopped from propagating. That results in this code

from IPython.display import display
from ipycanvas import Canvas
from ipyevents import Event

canvas = Canvas(width=500, height=48)

canvas.font = "32px serif"
canvas.fill_style = "black"
mon = Event(source=canvas, watched_events=['keyup', 'keydown'], wait = 1000//30)

def handle_event(event):
    global canvas
    if event['type'] == "keydown":
        canvas.clear()
        canvas.fill_text(f"last_pressed: {event['key']}", 0, 32)

mon.on_dom_event(handle_event)

display(canvas)

scrolling the notebook when the up or down arrow keys are pressed.