使用 vb.net 发送 ctrl+down​​ 键

发布于 2024-09-07 21:30:50 字数 1850 浏览 4 评论 0原文

这是我的代码..由于某种原因它不起作用

 Public Class Form1

    Private Declare Auto Function SendMessage Lib "user32.dll" ( _
ByVal hwnd As IntPtr, _
ByVal wMsg As Int32, _
ByVal wParam As Int32, _
ByVal lParam As Int32 _
) As Int32

    Private Const WM_KEYDOWN = &H100
    Private Const WM_KEYUP = &H101
    Private Const VK_SPACE = &H20
    Private Const VK_CONTROL = &H11
    Private Const VK_LEFT = &H25
    Private Const VK_UP = &H26
    Private Const VK_RIGHT = &H27
    Private Const VK_DOWN = &H28

    Private Sub Timer1_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer1.Tick


        Dim p As Process
        Dim title As String
        Dim handle As IntPtr

        For Each p In Process.GetProcessesByName("winamp")

            title = p.MainWindowTitle
            handle = p.MainWindowHandle

            If InStr(title, "Britney") Then

                SendMessage(handle, WM_KEYDOWN, VK_SPACE, 0&)
                SendMessage(handle, WM_KEYUP, VK_SPACE, 0&)

                SendMessage(handle, WM_KEYDOWN, VK_CONTROL, 0)
                SendMessage(handle, WM_KEYDOWN, VK_DOWN, 0)
                SendMessage(handle, WM_KEYUP, VK_CONTROL, 0)
                SendMessage(handle, WM_KEYUP, VK_DOWN, 0)

                SendMessage(handle, WM_KEYDOWN, VK_CONTROL, 0)
                SendMessage(handle, WM_KEYDOWN, VK_DOWN, 0)
                SendMessage(handle, WM_KEYUP, VK_CONTROL, 0)
                SendMessage(handle, WM_KEYUP, VK_DOWN, 0)

                SendMessage(handle, WM_KEYDOWN, VK_CONTROL, 0)
                SendMessage(handle, WM_KEYDOWN, VK_DOWN, 0)
                SendMessage(handle, WM_KEYUP, VK_CONTROL, 0)
                SendMessage(handle, WM_KEYUP, VK_DOWN, 0)


            End If

        Next



    End Sub
End Class

This is my code.. for some reason it is not working

 Public Class Form1

    Private Declare Auto Function SendMessage Lib "user32.dll" ( _
ByVal hwnd As IntPtr, _
ByVal wMsg As Int32, _
ByVal wParam As Int32, _
ByVal lParam As Int32 _
) As Int32

    Private Const WM_KEYDOWN = &H100
    Private Const WM_KEYUP = &H101
    Private Const VK_SPACE = &H20
    Private Const VK_CONTROL = &H11
    Private Const VK_LEFT = &H25
    Private Const VK_UP = &H26
    Private Const VK_RIGHT = &H27
    Private Const VK_DOWN = &H28

    Private Sub Timer1_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer1.Tick


        Dim p As Process
        Dim title As String
        Dim handle As IntPtr

        For Each p In Process.GetProcessesByName("winamp")

            title = p.MainWindowTitle
            handle = p.MainWindowHandle

            If InStr(title, "Britney") Then

                SendMessage(handle, WM_KEYDOWN, VK_SPACE, 0&)
                SendMessage(handle, WM_KEYUP, VK_SPACE, 0&)

                SendMessage(handle, WM_KEYDOWN, VK_CONTROL, 0)
                SendMessage(handle, WM_KEYDOWN, VK_DOWN, 0)
                SendMessage(handle, WM_KEYUP, VK_CONTROL, 0)
                SendMessage(handle, WM_KEYUP, VK_DOWN, 0)

                SendMessage(handle, WM_KEYDOWN, VK_CONTROL, 0)
                SendMessage(handle, WM_KEYDOWN, VK_DOWN, 0)
                SendMessage(handle, WM_KEYUP, VK_CONTROL, 0)
                SendMessage(handle, WM_KEYUP, VK_DOWN, 0)

                SendMessage(handle, WM_KEYDOWN, VK_CONTROL, 0)
                SendMessage(handle, WM_KEYDOWN, VK_DOWN, 0)
                SendMessage(handle, WM_KEYUP, VK_CONTROL, 0)
                SendMessage(handle, WM_KEYUP, VK_DOWN, 0)


            End If

        Next



    End Sub
End Class

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文