To delete shapes with the keyboard you first need to wrap the div inside some html element that can be focused since divs do not support focus, in this example I use a button, then access the button’s keyup event and well the rest of the code is easy To understand, as for the annotations, they cannot be selected like the shapes (I think) but you could activate their click event using the captureevents property and in this way you will have access to the plotly_clickannotation event and when you click on any annotation you save the value or index of the annotation to be able to delete it in the button event