Stylus/Pen 离开屏幕时的 WPF 手写笔事件

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

是否可以对 stylus/pen 未触摸屏幕时发生的按钮按下(即触控笔按钮之一,而不是某些应用程序中的按钮)做出反应(通过 StylusButtonDown 等,或替代方法) ,即悬停在笔记本电脑范围内的某个地方?这些似乎只有在笔尖实际接触屏幕表面时才会触发。具体来说,我不需要知道按钮的位置。就是当桶形按钮被按下时。

我正在使用 Microsoft Surface 和它附带的 Surface Pen,如果这有什么不同的话。我不需要它是跨平台的、便携的或任何东西。其实其他语言(C++等)的解决方案都可以。非常欢迎 Hacky 解决方案。

据我所知,Microsoft Surface 屏幕周围没有传感器。所以不,当它们靠近屏幕时,没有任何事件会对 stylus/pen 做出反应。

尽管如此,如果您是一名工程师,您可能会自己创建一些传感器,然后创建会对这些事情做出反应的事件。

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.

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)

This is how it could work, you will need to keep this software 运行 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.

我看到的唯一方法是自己为按钮整合传感器,因为它已经使用蓝牙或 WiFi 连接,所以使用所需的三角测量方法来校准设备。好吧,我认为这是一个老掉牙的答案,因为 Microsoft Surface 屏幕周围没有传感器。

如果您真的在寻找 "hacky solution",那么我有一个想法,但这将是一种非常肮脏的方式。 尽管不存在支持按钮的 api ,但即使手写笔未触摸屏幕,系统也会响应按下按钮。您可以创建一个在启动时读取以下命令行参数的应用程序:ClickOnce、DoubleClick、PressAndHold。根据提供的参数,应用程序应向您的主应用程序发送适当的消息。 现在您可以转到 "pen settings" 并根据操作,select 到 运行 上面的应用程序使用适当的参数。

AutoHotKey就是答案!

AutoHotKey 是一种开源工具,可帮助创建对 Windows 输入设备事件的自定义自动响应。

AutoHotKey 支持 Surface 触控笔。也支持笔离屏场景

Surface Pen 通过蓝牙连接到 Windows,信号范围为数米。因此,在技术上可以使用 Surface 触控笔作为 Windows!

的遥控器

最受欢迎的场景之一是使用 Surface Pen 作为演示控制器

这是一个有效的 AutoHotKey 脚本,用于使用 Surface Pen 控制 Powerpoint 演示文稿:

;  File name: surface-pen-slide-show-control.ahk
;
;  This program helps the presenter scroll through slides, using Surface Pen
;  
;  Single-click on pen button to scroll forward
;  Double-click on pen button to scroll backward
;

#NoEnv
SendMode Input
SetWorkingDir %A_ScriptDir%

#IfWinActive ahk_class screenClass
#F20::
  Send, {Right}
Return

#F19::
  Send, {Left}
Return

更多信息和帮助: