vb.net – VB模拟按键

在我的程序中,我想模拟按下MediaPlayPause键.就像一张纸条,我不想检查按键是否按下或按下,我想通过我的程序按键.

我尝试过SendKeys.Send,但特殊键仅限于{Enter}和{Tab}等.

好的,我从这个答案中移植了c#代码https://stackoverflow.com/a/7182076/2000557

我不知道VB.Net,但使用本指南复制并不太难:http://msdn.microsoft.com/en-us/library/172wfck9.aspx

无论如何,我通过点击事件在表单上放了一个按钮.

Imports System.Runtime.InteropServices

Public Class Form1

    'this constant represents the hex value for the key to send to user32.dll
    Const APPCOMMAND_MEDIA_PLAY_PAUSE = &HE0000
    'this constant represents which command. Sort of like the function in user32.dll we are calling.
    Const WM_APPCOMMAND = &H319

    'this declares the user32.dll call to SendMessageW we are making
    Declare Auto Function SendMessageW Lib "user32.dll" Alias "SendMessageW" (
    ByVal hWnd As Integer,ByVal Msg As Integer,ByVal wParam As Integer,ByVal lParam As Integer) As Integer

    Private Sub Button1_Click(sender As Object,e As EventArgs) Handles Button1.Click
        'call the SendMessage function with the current window handle,the command we want to use,same handle,and the button we want to press
        SendMessageW(Handle,WM_APPCOMMAND,Handle,APPCOMMAND_MEDIA_PLAY_PAUSE)
    End Sub
End Class

我通过打开WMplayer测试了它,按钮播放/暂停了我的音乐.如果您需要任何其他帮助,请告诉我.如果要实现其他密钥,请参考以下内容http://msdn.microsoft.com/en-us/library/windows/desktop/ms646275(v=vs.85).aspx

相关文章

Format[$] ( expr [ , fmt ] ) format 返回变体型 format$ 强制返回为文本 --------------------------...
VB6或者ASP 格式化时间为 MM/dd/yyyy 格式,竟然没有好的办法, Format 或者FormatDateTime 竟然结果和...
在项目中添加如下代码:新建窗口来显示异常信息。 Namespace My ‘全局错误处理,新的解决方案直接...
转了这一篇文章,原来一直想用C#做k3的插件开发,vb没有C#用的爽呀,这篇文章写与2011年,看来我以前没...
Sub 分列() ‘以空格为分隔符,连续空格只算1个。对所选中的单元格进行处理 Dim m As Range, t...
  窗体代码 1 Private Sub Text1_OLEDragDrop(Data As DataObject, Effect As Long, Button As Integ...