首页 > 解决方案 > OneNote 在 AHK 之前拦截笔光标?

问题描述

手掌拒绝在我的笔记本电脑上是垃圾,所以我禁用了 HID 触摸屏以使其只有笔输入寄存器。因此,我使用 AHK 制作了一个脚本,该脚本将在用户按下后滚动页面ALT,并在第二次按下时禁用滚动ALT

它工作得很好,除了在 OneNote(Win 10 应用程序)中,笔光标输入被 OneNote 劫持。例如,如果我创建一个ToolTip, %xPos% %yPos%,那么当我的笔光标悬停在 OneNote 窗口上方的任何位置时,它不会更新。这之外的任何地方都可以正常工作。

如何让 AHK 在 OneNote 获取之前窃取笔光标输入?

isTabletMode := 1
penScrollActive := 0

#MaxThreadsPerHotkey 2   ; Allows a second instance to modify penScrollActive while PenScroll is looping.
$Alt::
    ; Check if PC is in tablet mode.
    ;   1 --> Tablet, 0 --> Desktop
    RegRead, isTabletMode, HKEY_CURRENT_USER\SOFTWARE\Microsoft\Windows\CurrentVersion\ImmersiveShell,TabletMode
    if(isTabletMode) {
        if(penScrollActive) {
            penScrollActive := 0  ; We are already scrolling, so turn it off.
        }
        else {
            penScrollActive := 1 ; We are not scrolling yet, so turn on pen scrolling.
        }
    GoSub PenScroll
    }
    else    ; If we aren't in tablet mode, then Alt should just send Alt
        Send, {Alt}
    return

PenScroll:
    loop {    ; For some reason, while() logic wasn't working, so this is a workaround. Breaks upon the conditional at bottom.
        MouseGetPos, mouseX, mouseY
        ToolTip, %mouseX% %mouseY%   ; For debugging: Output what cursor pos registers as.  (This isn't working in OneNote when using the pen input as a cursor (eg. hover) ).
        Sleep, 20
        MouseGetPos, mouseX_new, mouseY_new
        if (mouseX_new - mouseX > 0)        ; Horizontal scrolling
            Send, {WheelLeft}
        else if (mouseX_new - mouseX < 0)
            Send, {WheelRight}
        if (mouseY_new - mouseY > 0)        ; Vertical scrolling
            Send, {WheelUp}
        else if (mouseY_new - mouseY < 0)
            Send, {WheelDown}
        if (penScrollActive = 0)            ; Conditional to break out
            break
    }
    return

; To Reload the script: Win+`
#`::Reload
Return

#If penScrollActive
LButton::Return

标签: autohotkey

解决方案


您可以尝试的一件事是我的 AHK 的AutoHotInterception库。您安装一个自定义设备驱动程序,然后您可以在操作系统下方的驱动程序级别挂钩输入事件。
它支持“绝对”(类似图形平板电脑)鼠标输入
您想要“订阅模式”端点


推荐阅读