2

I was wondering if you can detect that an event comes from a passive pen from modern web browsers.

For example on a surface hub, in Edge, you have event.pointerType === 'pen' to distinguish touches made with pen vs those made with a finger but I don't know if you can do the same with any pen on any browser in any OS.

I haven't found any information about it but I am not sure I looked at the right places.

KspR
  • 51
  • 4
  • My guess is that this is a non-standard feature that only Edge implements. – Sumner Evans Aug 15 '17 at 15:21
  • 1
    It's actually in w3c https://www.w3.org/TR/pointerevents/. But I am not sure which pens / oses are actually able to pass the right events to the browsers, and what are the exact conditions for the pen event to be actually sent correctly all the way to the browser. – KspR Aug 15 '17 at 18:46

2 Answers2

2

event.pointerType is supported by most modern browsers:

https://developer.mozilla.org/en-US/docs/Web/API/PointerEvent/pointerType

In Firefox it requires that dom.w3c_pointer_events.enabled be set to true in about:config. It presents mouse, pen, and touch as values.

ryanpcmcquen
  • 6,285
  • 3
  • 24
  • 37
  • 1
    Yes but are OSes actually able to pass passive pen touches as pen events to browsers?I understand modern browser expose the pointerType attribute, but for it to get the correct value they have to receive it this way from OSes as well. If the OS doesn't detect the pen, it will send a touch type event to the browser who will in its turn set the pointerType attribute to 'touch', no? – KspR Aug 15 '17 at 18:44
0

yes and no! passive pen is interpreted as touch BUT you can use pointerevent width and height to guess a touch is passive pen or simple touch. assuming finger has bigger width and height than pen

Ali Haghighi
  • 143
  • 3
  • 11