在我的程序中,我想模拟按下
MediaPlayPause
键的操作。请注意,我不想检查该键是否已按下或被按下,而是通过我的程序按下该键。
我尝试过使用SendKeys.Send,但特殊键仅限于{Enter}
和{Tab}
等。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