admin管理员组文章数量:1401241
I am working on a web application where the user should be abled to sign a document on a tablet. We use the Galaxy Tab 12.2 because the S-Pen has the desired precision.
The canvas where i draw on uses listens to the touch
events to draw on the canvas.
canvas.addEventListener('touchstart', handleStart);
canvas.addEventListener('touchmove' , handleMove);
The problem here is, that if the user touches the canvas with his fingers, the canvas will draw lines there.
Is there a way to differentiate between S-Pen events and 'normal' touch events?
I know that on the Surface Pro 3 with Internet Expoler I can handle Pen input different from finger input.
I am working on a web application where the user should be abled to sign a document on a tablet. We use the Galaxy Tab 12.2 because the S-Pen has the desired precision.
The canvas where i draw on uses listens to the touch
events to draw on the canvas.
canvas.addEventListener('touchstart', handleStart);
canvas.addEventListener('touchmove' , handleMove);
The problem here is, that if the user touches the canvas with his fingers, the canvas will draw lines there.
Is there a way to differentiate between S-Pen events and 'normal' touch events?
I know that on the Surface Pro 3 with Internet Expoler I can handle Pen input different from finger input.
Share Improve this question asked Feb 27, 2015 at 11:46 chillichiefchillichief 1,21213 silver badges22 bronze badges3 Answers
Reset to default 6Ok so i found a solution myself that is working pretty well.
The SPen fires an ontouch
event with radiusX
and radiusY
= 0.
The events that are triggered with a finger always have a radius > 0. So all that was to do is add
if(e.targetTouches[0].radiusX === 0)
into the event handlers to draw on my canvas.
Check out this Jsfiddle
The S-Pen should fire an onMouseOver
event when it gets close to the screen (depending on browser & S-Pen version), you can take advantage of that by storing a global variable isSPen = false
and having a global onMouseOver
event setting that variable to true
. Try different browsers and see which ones will deliver the event, usually the stock browser always works best.
If that doesn't work, you may need to host your webpage inside an app container; Android has an OnHoverListener
that picks up the S-Pen. You can use a full-screen WebView and municate to it with Android's JavaScript messaging API: Example
Hope I helped you out, good luck
The pointerType property can be accessed through the 'pointerdown' event instead of relying on the 'mousedown' event.
本文标签: javascriptUsing Samsung SPen in CanvasStack Overflow
版权声明:本文标题:javascript - Using Samsung S-Pen in Canvas - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1744259827a2597657.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论