如何使用Visual Basic禁用鼠标

时间:2015-09-04 23:09:02

标签: vb.net windows

我在autohotkey中写了一个技术工具箱,但很多AV软件已经开始杀掉用autohotkey编写的东西,所以我在VB中重做它.net 我已经能够完成大部分工作,但几乎每个使用我的工具箱的人都使用的工具之一是禁用鼠标的热键。我们正在使用logmein进行远程工作,它只是阻止客户杀死病毒删除工具。

我找到了一种使用VB.net禁用鼠标和键盘的方法,但它完全禁用它而不仅仅是为了客户,我只是想让它禁用鼠标而不是键盘,因为它杀死了两个热键再次启用它们不起作用。

以下是我一直用于代码的内容。

Private Declare Function GetAsyncKeyState Lib "user32" (ByVal vkey As Long) As Integer
Private Declare Function BlockInput Lib "user32" Alias "BlockInput" (ByVal fBlock As Integer) As Integer
Private Declare Function ShowCursor Lib "user32" (ByVal lShow As Long) As Long
Private Sub Timer1_Tick(sender As Object, e As EventArgs) Handles Timer1.Tick
    Timer1.Enabled = True
    Timer1.Interval = 1
    Dim mkey As Boolean
    Dim dkey As Boolean
    Dim ekey As Boolean
    mkey = GetAsyncKeyState(Keys.M)
    dkey = GetAsyncKeyState(Keys.D)
    ekey = GetAsyncKeyState(Keys.E)
    If mkey And dkey = True Then
        BlockInput(1)
        ShowCursor(0)
    End If

    If mkey And ekey = True Then
        BlockInput(0)
        ShowCursor(1)
    End If
End Sub

1 个答案:

答案 0 :(得分:1)

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

启用

BlockInput 1

禁用

BlockInput 0