[w3c/uievents] Wheel event: determine difference between trackpad and mouse events (Issue #337)

Currently with web technologies, there is no way of knowing the difference between mouse events and trackpad events. This is creating a lot of challenges for us as developers of 3D applications.

To briefly explain our application:
- a two-finger drag on a touchpad pans the camera
- a scroll on the mouse zooms the camera

However, as far as the browser is concerned, these are exactly the same mouse event. In order to tell the difference, we take a sample of deltas from the wheel event and try our best to guess the hardware being used based on our own research of devices. You can see what sort of things we're doing by looking at our tests (below).

Some things that I can think of that would be very useful:
- A simple flag attached to mouse events (e.g. `isTrackpad`)
- Multi-touch data from the trackpad (same as [touchscreens on the web](https://developer.mozilla.org/en-US/docs/Web/API/Touch_events/Multi-touch_interaction))
- A device name attached to mouse events (e.g. `Apple Magic Mouse`, `Logitech XX`)

Related issues:
https://github.com/w3c/pointerevents/issues/462
https://github.com/w3c/pointerevents/issues/206

```js
test("Is from wheel if deltas have fractional components", () => {
  const deltas = [100.5, 100.3, 100.1231]
  const result = checkDeltasAreFromWheel(deltas)
  expect(result).toEqual(true)
})

test("Is from wheel if deltas are all the same (absolutely)", () => {
  const deltas = [100, 100, -100]
  const result = checkDeltasAreFromWheel(deltas)
  expect(result).toEqual(true)
})

test("Is NOT from wheel if deltas are all the same but low", () => {
  const deltas = [1, 1, 1, 1, 1, 1, 1]
  const result = checkDeltasAreFromWheel(deltas)
  expect(result).toEqual(false)
})

test("Is NOT from wheel if most the deltas are low", () => {
  const deltas = [11, 11, 11, 11, 11, 11, 10, 50, 51]
  const result = checkDeltasAreFromWheel(deltas)
  expect(result).toEqual(false)
})

test("Is NOT from wheel if most deltas are different, but not all", () => {
  const deltas = [25, 25, 26, 27, 28]
  const result = checkDeltasAreFromWheel(deltas)
  expect(result).toEqual(false)

  const deltas2 = [23, 24, 22, 25, 25]
  const result2 = checkDeltasAreFromWheel(deltas2)
  expect(result2).toEqual(false)
})

test("Is from wheel if deltas have some simple relationship 1.5x / 2x / 3x / 4x / 0.5 / 0.666 / 0.333 / 0.25", () => {
  const deltas = [150, 300, -450, 150, 450, 300]
  const result = checkDeltasAreFromWheel(deltas)
  expect(result).toEqual(true)
})

test("Is not from wheel if simple relationship only happens once in sample", () => {
  const deltas = [-13, -14, 50, 100, 102, 33]
  const result = checkDeltasAreFromWheel(deltas)
  expect(result).toEqual(false)
})

test("Is NOT wheel if deltas are completely different", () => {
  const deltas = [101, 201, -101, 51, 201]
  const result = checkDeltasAreFromWheel(deltas)
  expect(result).toEqual(false)

  const deltas2 = [-26, -7, -3, -1]
  const result2 = checkDeltasAreFromWheel(deltas2)
  expect(result2).toEqual(false)
})

test("Sample of deltas from magic mouse", () => {
  const deltas = [-13, -14, -48, -20, -21, -74, -29, -32, -105, -35]
  const result = checkDeltasAreFromWheel(deltas)
  expect(result).toEqual(false)
})
```

-- 
Reply to this email directly or view it on GitHub:
https://github.com/w3c/uievents/issues/337
You are receiving this because you are subscribed to this thread.

Message ID: <w3c/uievents/issues/337@github.com>

Received on Wednesday, 30 November 2022 08:36:21 UTC