0
真的很簡單。我希望應用程序能夠保持監視KeyDown事件,即使沒有焦點。在Visual Basic中執行沒有焦點的KeyDown函數
Private Sub Form1_KeyDown(sender As Object, e As System.Windows.Forms.KeyEventArgs) Handles Me.KeyDown
Select Case e.KeyData
Case Keys.MediaStop
PictureBox2_Click(sender, e)
Case Keys.MediaPlayPause
PauseToolStripMenuItem_Click(sender, e)
Case Keys.MediaNextTrack
SkipTrackToolStripMenuItem_Click(sender, e)
Case Keys.MediaPreviousTrack
PreviousTrackToolStripMenuItem_Click(sender, e)
End Select
End Sub
上述代碼適用於音樂播放器。當按下媒體鍵時會調用函數('Fn'+'Home','Fn'+'Pg Up'...等等)
在之前的評論中,有人建議尋找WH_KEYBOARD_LL解決方案,但我如果我誠實的話,我真的不太瞭解它。
UPDATE:
建議的link不是很大的「作爲任何」關鍵字不支持「聲明」的功能。
這是我在多大程度上與它得到...
Public Declare Function CallNextHookEx Lib "user32" (ByVal hHook As Long, ByVal ncode As Long, ByVal wParam As Long, lParam As **Any**) As Long
Public Declare Function UnhookWindowsHookEx Lib "user32" (ByVal hHook As Long) As Long
Public Declare Function SetWindowsHook Lib "user32" Alias "SetWindowsHookA" (ByVal nFilterType As Long, ByVal pfnFilterProc As Long) As Long
Public Declare Function SetWindowsHookEx Lib "user32" Alias "SetWindowsHookExA" (ByVal idHook As Long, ByVal lpfn As Long, ByVal hmod As Long, ByVal dwThreadId As Long) As Long
Public Declare Sub CopyMemory Lib "kernel32" Alias "RtlMoveMemory" (Destination As **Any**, Source As **Any**, ByVal Length As Long)
**Global** Const WH_KEYBOARD_LL = 13
Public Const HC_ACTION = 0
Structure HookStruct
Dim vkCode As Long
Dim scancode As Long
Dim flags As Long
Dim time As Long
Dim dwExtraInfo As Long
End Structure
的錯誤是Visual Studio是強調都寫在大膽 在懸停「任意」它給我的消息「‘作爲任何’不‘聲明’聲明支持」
在「全球性」的懸停它給「語法錯誤」
請參見上面 –
檢查 1. http://msdn.microsoft.com/en-us/library/347xhy8d.aspx 2. http://www.codeproject.com/Articles更新/ 8641 /等效的CopyMemory-in-NET ...... 對於.NET版本,請檢查以下鏈接:http://sim0n.wordpress.com/2009/03/28/vbnet-keyboard-hook -類/ – rags