Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

WPF Stylus Events when Stylus/Pen is away from the screen

Tags:

Is it possible to react (via StylusButtonDown etc., or alternatives) to button presses (i.e. one of the stylus buttons, not buttons in some app) that happen when the stylus/pen is not touching the screen, i.e. hovering in the air somewhere in range of the notebook? Those only seem to trigger if the pen tip is actually touching the surface of the screen. Specifically, I do not need to know about the position of the button. Just literally when the barrel button is pressed.

I'm using a Microsoft Surface and the Surface Pen that comes with it in particular, if that makes any difference. I don't need it to be cross-platform, portable or anything. In fact, solutions in other languages (C++, etc.) are OK. Hacky solutions are very welcome.

like image 722
TravisG Avatar asked Jan 17 '20 10:01

TravisG


1 Answers

I have might have solution that would work with currently used technologies such as bluetooth and Wifi that is in pen and your Microsoft Surface. But you will need to program some parts on your own (most of mentioned techniques are in open source libraries).

After you pair your,pen with Surface you should be connected with Wifi and bluetooth to the pen.

1. Option

There is good article, explaining bluetooth triangulation that we will use for triangulating pen in close area, except we will use bluetooth and wifi (we dont have 3th point) so it will not be so precise as 3 points. But with 2 points you can actually measure distance by this table and find where is theirs intersection, in such small space its doable.

Measure Table

Use similar method with Wifi for second triangulation point, you can see source codes for Wifi triangluation down there.

Next step will be calibrating the position of pen in holder, that means that the pen will be at one side of the Surface(for simplification lets assume its only at right shorter side)

from this you can compute area of screen

Allowed area:

offsetHeightOfPenScreenRation = ScreenHeight - penHardwareHeight

NonValidX = StartpenPositionX - ScreenWidth < penPositionX or StartpenPositionX < penPositionX

NonValidY = StartpenPositionY - ScreenHeight < penPositionY or StartpenPosition+offsetHeightOfPenScreenRation < penPositionY

penIsClose = not ( NonValidX or NonValidY)

Trianglualtion

This is how it could work, you will need to keep this software running in background and it could have some serious impact on battery, you will need external wifi adapter for internet.

I dont have Microsoft surface so i cant code it myself cause i dont have device to try it on, but this is working idea. With little tuning of precision it could be really precise positioning.

2. Option

Wifi triangluation: https://github.com/kevindu/wifi-ap-positioning can be maybe used alone and you can transfer location through the bluetooth if you can get into a firmware of pen, but this option will not be so precise.

like image 125
Jiri Otoupal イり オトウパー Avatar answered Sep 19 '22 17:09

Jiri Otoupal イり オトウパー