1

Basicly in javascript in my html I want to be able to do something like this.

var penpressure = inputDevice.getPressure();
console.log(penpressure);

Ideally this would work for other kinds of pressure inputs as well, wacom on desktop machines (without a plugin) just from the normal driver. Different tablets with stylus pens etc..

rende
  • 31
  • 5
  • Someone else asked this for desktops - and required a wacom plugin. http://stackoverflow.com/questions/10507341/can-i-recognise-graphic-tablet-pen-pressure-in-javascript – Jeff Clayton Aug 17 '14 at 17:55
  • The wacom plugin is not available on the linux platform. Requiring a plugin also breaks user experience. Installing a driver is already tedious. – rende Aug 17 '14 at 17:58
  • If you're writing a native app its just part of the touch event. This is one of the reasons why writing apps in non-native code is generally a bad idea- you have to code for the lowest common denominator. – Gabe Sechan Aug 17 '14 at 18:01
  • I think you are out of luck using a web browser for the interface. It may be possible to instead check for the amount of time while between 'stylus down' and 'stylus up' as a workaround for pressure. A longer 'press' would then be like a stronger one. – Jeff Clayton Aug 17 '14 at 18:12
  • I opted out of learning native code as I prefer javascript. I also see now that the W3C Pointer spec won't be in chrome? http://lists.w3.org/Archives/Public/public-pointer-events/2014JulSep/0051.html – rende Aug 17 '14 at 18:17
  • In the past, on Microsoft platforms, it was possible to have an activex control available [actually it still is for that platform - an example being a TIFF reader activex for windows internet explorer], in which case you could use that to interface the OS, at least up and excluding security concerns - which is really the kind of thing you need. You could 'click to install' and it would work from then on. Java can probably do that as well, if you really want it that is a hit you have to take for 'user experience' as it only needs 'downloaded and installed' the first time. – Jeff Clayton Aug 17 '14 at 18:17
  • The length of stylus time option I mentioned is used in paint applications sometimes. The longer you hold the pointer on the picture, the thicker the paint becomes at that spot. – Jeff Clayton Aug 17 '14 at 18:28

1 Answers1

0
const HAS_POINTER = ('onpointermove' in window);
window.addEventListener(HAS_POINTER ? 'pointermove' : 'mousemove', (e) => {
  const pressure = HAS_POINTER ? e.pressure : 1;
  context.lineWidth = pressure * YOUR_STROKE_SIZE;
  draw();
}

Pressure max is 1

Phil Dukhov
  • 67,741
  • 15
  • 184
  • 220
joseluismurillorios
  • 1,005
  • 6
  • 11