"BlockInput" 函数在程序中不起作用

"BlockInput" Function is Not Working in Program

我正在创建一个程序,可以在用户要求的任何地方点击屏幕。但是我想在程序执行单击时禁用鼠标 movement/clicking,否则如果用户在程序执行单击时移动鼠标,它可能会将鼠标拖离鼠标应该单击的位置。

目前我尝试使用:

Private Declare Function BlockInput Lib "user32" Alias "BlockInput" (ByVal fBlock As Boolean) As Boolean

&

Private Declare Function BlockInput Lib "user32" Alias "BlockInput" (ByVal fBlock As Integer) As Integer

然后根据我声明“BlockInput”函数的方式调用BlockInput(True/False)BlockInput(1/0)

目前,当我在屏幕上拖动鼠标时,都不会阻止鼠标移动。

是否需要在我的代码中包含一些内容才能使此功能正常工作?我知道以这种方式禁用鼠标也可能会禁用程序本身执行点击,但我什至无法测试它,因为我无法做到这一点。

感谢任何帮助,谢谢!

测试并让我重新启动 :) 小心。正在努力赢得 10

Imports System.Runtime.InteropServices

Public Class Form1

<DllImport("user32.dll", EntryPoint:="BlockInput")> _
Private Shared Function BlockInput(<MarshalAs(UnmanagedType.Bool)> ByVal fBlockIt As Boolean) As <MarshalAs(UnmanagedType.Bool)> Boolean
End Function

Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
    BlockInput(True)
End Sub

End Class