# Cancel highlight/html5 drag/autoscroll events that are in progress (undo events started by mousedown)

**URL:** <https://discourse.mozilla.org/t/cancel-highlight-html5-drag-autoscroll-events-that-are-in-progress-undo-events-started-by-mousedown/7823>\
**Category:** Development\
**Created:** [March 30, 2016, 1:52am UTC](https://discourse.mozilla.org/t/cancel-highlight-html5-drag-autoscroll-events-that-are-in-progress-undo-events-started-by-mousedown/7823 "2016-03-30T01:52:04Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![noitidart](https://avatars.discourse-cdn.com/v4/letter/n/9f8e36/32.png) [@noitidart](https://discourse.mozilla.org/u/noitidart)\
**Post date:** [March 30, 2016, 1:52am UTC](https://discourse.mozilla.org/t/cancel-highlight-html5-drag-autoscroll-events-that-are-in-progress-undo-events-started-by-mousedown/7823/1 "2016-03-30T01:52:10Z")

</div>

I have a gesture addon and the trigger to is the primary mouse button + wheel. Once the wheel is scrolled while the primary mouse button is held, all further mouse events are blocked. Until the primary mouse button is released.

However I need to cancel the current highlight in progress, the html5 drag in progress, the autoscroll in progress if any, and ideally any other events initiate by the mousedown. The way I currently do it is use `nsIDOMWindowUtils` to send a `mouseup` event (and tap into code to cancel autoscroll) but I dislike this method:

```
setTimeout(function () {
    var cwin = Services.wm.getMostRecentWindow('navigator:browser').gBrowser.selectedBrowser.contentWindow;
    var utils = cwin.QueryInterface(Ci.nsIInterfaceRequestor).getInterface(Ci.nsIDOMWindowUtils);
    utils.sendMouseEvent('mouseup', 1, 1, triggerButtonNumber, 1, 0);
    console.error('done');
}, 4000)

```

I was wondering if anyone could brainstorm with me some other ideas please?

I have tried suppressing events with [nsIDOMWindowUtils :: supressEventHandling](https://developer.mozilla.org/en-US/docs/Mozilla/Tech/XPCOM/Reference/Interface/nsIDOMWindowUtils#suppressEventHandling%28%29) but on unsupress the events continue from where they left off.

Basically what I’m trying to do is undo/cancel/preventDefault any events started by the “Down” of the first mouse button.

---

<div class="post-metadata">

**Author:** ![quicksaver](https://sea1.discourse-cdn.com/flex001/user_avatar/discourse.mozilla.org/quicksaver/32/21077_2.png) [@quicksaver](https://discourse.mozilla.org/u/quicksaver)\
**Post date:** [March 30, 2016, 8:22pm UTC](https://discourse.mozilla.org/t/cancel-highlight-html5-drag-autoscroll-events-that-are-in-progress-undo-events-started-by-mousedown/7823/2 "2016-03-30T20:22:01Z")

</div>

The first (and pretty much only) thing that comes to mind is simulating an Esc keypress. (Almost?) all of such actions are cancelled by hitting esc.

---

<div class="post-metadata">

**Author:** ![noitidart](https://avatars.discourse-cdn.com/v4/letter/n/9f8e36/32.png) [@noitidart](https://discourse.mozilla.org/u/noitidart)\
**Post date:** [March 30, 2016, 10:06pm UTC](https://discourse.mozilla.org/t/cancel-highlight-html5-drag-autoscroll-events-that-are-in-progress-undo-events-started-by-mousedown/7823/3 "2016-03-30T22:06:55Z")

</div>

Thanks that’s a great idea! It might also stop the page loading ☹ I’ll play with it to see if I can make it stop everything but the page load it’s a great idea!

---

<div class="post-metadata">

**Author:** ![quicksaver](https://sea1.discourse-cdn.com/flex001/user_avatar/discourse.mozilla.org/quicksaver/32/21077_2.png) [@quicksaver](https://discourse.mozilla.org/u/quicksaver)\
**Post date:** [March 30, 2016, 10:42pm UTC](https://discourse.mozilla.org/t/cancel-highlight-html5-drag-autoscroll-events-that-are-in-progress-undo-events-started-by-mousedown/7823/4 "2016-03-30T22:42:00Z")

</div>

Good point, I didn’t consider esc might do a little too much.
