使用visual basic使鼠标滚动

问题描述 投票:-3回答:1

我找不到任何相关内容,所以我在这里问。我知道如何移动我的鼠标并发送点击等但我想知道是否可以使用visual basic使鼠标向上或向下滚动。选择滚动距离也很棒。 (只是为了澄清我不想在表单中做任何事情,我想在表单之外滚动)

我希望有一个人可以帮助我 :)

vb.net
1个回答
0
投票

也许flag MOUSEEVENTF_WHEEL of the mouse event function就是你要找的。

here,我得到了一个可以帮助的样本(我还没有测试过)。

Imports System.Runtime.InteropServices

Public Class Form1
    Private WithEvents Tmr As New Timer With {.Interval = 2000}

    Private Const MOUSEEVENTF_WHEEL As Integer = &H800 'The amount of movement is specified in mouseData.
    Private Const MOUSEEVENTF_HWHEEL As Integer = &H1000 'Not available for 2000 or XP

    <DllImport("user32.dll", EntryPoint:="mouse_event")> _
    Private Shared Sub mouse_event(ByVal dwFlags As UInteger, ByVal dx As Integer, ByVal dy As Integer, ByVal dwData As Integer, ByVal dwExtraInfo As UInteger)
    End Sub

    Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        Me.KeyPreview = True
        Tmr.Start()
    End Sub

    Private Sub Tmr_Tick(ByVal sender As Object, ByVal e As System.EventArgs) Handles Tmr.Tick
        MouseScroll(False, 10) 'scrolls Down 10 wheel clicks
        'MouseScroll(True, 1) 'scrolls Up 1 wheel click
    End Sub

    Private Sub MouseScroll(ByVal up As Boolean, ByVal clicks As Integer)
        If up Then
            mouse_event(MOUSEEVENTF_WHEEL, 0, 0, (clicks * 120), 0)
        Else
            mouse_event(MOUSEEVENTF_WHEEL, 0, 0, -(clicks * 120), 0)
        End If
    End Sub
End Class
© www.soinside.com 2019 - 2024. All rights reserved.