vb中全局快捷键的问题
我用vb做了一个程序,其中插入了一个控件:windowsmediaplayer,名称是WindowsMediaPlayer1。怎么做全局快捷键,使当按下Ctrl+Alt+...
我用vb做了一个程序,其中插入了一个控件:windows media player,名称是WindowsMediaPlayer1。怎么做全局快捷键,使当按下Ctrl+Alt+↑增大音量,当按下Ctrl+Alt+↓减小音量?谢啦~
貌似都没有做到全局快捷键···· 展开
貌似都没有做到全局快捷键···· 展开
4个回答
展开全部
需要一个时间控件 Timer1
'api声明
Private Declare Function GetAsyncKeyState Lib "user32" (ByVal vkey As Long) As Integer '热键
Private Sub Form_Load()
Timer1.Interval=100
Timer1.Enabled = true
End Sub
Private Sub Timer1_Timer()
If GetAsyncKeyState(vbKeyMenu) And GetAsyncKeyState(vbKeyControl) And GetAsyncKeyState(vbKeyUp) Then '按下Ctrl+Alt+↑
If WindowsMediaPlayer1.settings.volume < 100 Then
WindowsMediaPlayer1.settings.volume = WindowsMediaPlayer1.settings.volume + 1
End If
End If
If GetAsyncKeyState(vbKeyMenu) And GetAsyncKeyState(vbKeyControl) And GetAsyncKeyState(vbKeyDown) Then '按下Ctrl+Alt+↓
If WindowsMediaPlayer1.settings.volume > 0 Then
WindowsMediaPlayer1.settings.volume = WindowsMediaPlayer1.settings.volume - 1
End If
End If
End Sub
楼下的老兄怎么Copy我的代码啊!
'api声明
Private Declare Function GetAsyncKeyState Lib "user32" (ByVal vkey As Long) As Integer '热键
Private Sub Form_Load()
Timer1.Interval=100
Timer1.Enabled = true
End Sub
Private Sub Timer1_Timer()
If GetAsyncKeyState(vbKeyMenu) And GetAsyncKeyState(vbKeyControl) And GetAsyncKeyState(vbKeyUp) Then '按下Ctrl+Alt+↑
If WindowsMediaPlayer1.settings.volume < 100 Then
WindowsMediaPlayer1.settings.volume = WindowsMediaPlayer1.settings.volume + 1
End If
End If
If GetAsyncKeyState(vbKeyMenu) And GetAsyncKeyState(vbKeyControl) And GetAsyncKeyState(vbKeyDown) Then '按下Ctrl+Alt+↓
If WindowsMediaPlayer1.settings.volume > 0 Then
WindowsMediaPlayer1.settings.volume = WindowsMediaPlayer1.settings.volume - 1
End If
End If
End Sub
楼下的老兄怎么Copy我的代码啊!
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
'以下保存在模块中
Public Declare Function SetWindowLong Lib "user32" Alias "SetWindowLongA" (ByVal hwnd As Long, ByVal nIndex As Long, ByVal dwNewLong As Long) As Long
Public Declare Function GetWindowLong Lib "user32" Alias "GetWindowLongA" (ByVal hwnd As Long, ByVal nIndex As Long) As Long
Public Declare Function CallWindowProc Lib "user32" Alias "CallWindowProcA" (ByVal lpPrevWndFunc As Long, ByVal hwnd As Long, ByVal Msg As Long, ByVal wParam As Long, ByVal lParam As Long) As Long
Public Declare Function RegisterHotKey Lib "user32" (ByVal hwnd As Long, ByVal id As Long, ByVal fskey_Modifiers As Long, ByVal vk As Long) As Long
Public Declare Function UnregisterHotKey Lib "user32" (ByVal hwnd As Long, ByVal id As Long) As Long
Public Const GWL_WNDPROC = (-4)
Public Const WM_HOTKEY = &H312
Public Const MOD_CONTROL = &H2
Public Const MOD_ALT = &H1
Public Const VK_UP = &H26
Public Const VK_DOWN = &H28
Public preWinProc As Long
Public Function wndproc(ByVal hwnd As Long, ByVal Msg As Long, ByVal wParam As Long, ByVal lParam As Long) As Long
If Msg = WM_HOTKEY Then
Select Case wParam
Case 0
If Form1.WindowsMediaPlayer1.settings.volume < 100 Then Form1.WindowsMediaPlayer1.settings.volume = Form1.WindowsMediaPlayer1.settings.volume + 1
Case 1
If Form1.WindowsMediaPlayer1.settings.volume > 0 Then Form1.WindowsMediaPlayer1.settings.volume = Form1.WindowsMediaPlayer1.settings.volume - 1
End Select
End If
wndproc = CallWindowProc(preWinProc, hwnd, Msg, wParam, lParam)
End Function
’以下保存在窗体中
Private Sub Form_Load()
preWinProc = GetWindowLong(Me.hwnd, GWL_WNDPROC) '获得窗口过程的地址
SetWindowLong Me.hwnd, GWL_WNDPROC, AddressOf wndproc '为窗口过程设定一个新的地址
RegisterHotKey Me.hwnd, 0, MOD_CONTROL + MOD_ALT, VK_UP
RegisterHotKey Me.hwnd, 1, MOD_CONTROL + MOD_ALT, VK_DOWN '登记热键
End Sub
Private Sub Form_Unload(Cancel As Integer)
UnregisterHotKey Me.hwnd, 0
UnregisterHotKey Me.hwnd, 1 '释放先前登记的热键
SetWindowLong Me.hwnd, GWL_WNDPROC, preWinProc '还原窗口过程地址
End Sub
Public Declare Function SetWindowLong Lib "user32" Alias "SetWindowLongA" (ByVal hwnd As Long, ByVal nIndex As Long, ByVal dwNewLong As Long) As Long
Public Declare Function GetWindowLong Lib "user32" Alias "GetWindowLongA" (ByVal hwnd As Long, ByVal nIndex As Long) As Long
Public Declare Function CallWindowProc Lib "user32" Alias "CallWindowProcA" (ByVal lpPrevWndFunc As Long, ByVal hwnd As Long, ByVal Msg As Long, ByVal wParam As Long, ByVal lParam As Long) As Long
Public Declare Function RegisterHotKey Lib "user32" (ByVal hwnd As Long, ByVal id As Long, ByVal fskey_Modifiers As Long, ByVal vk As Long) As Long
Public Declare Function UnregisterHotKey Lib "user32" (ByVal hwnd As Long, ByVal id As Long) As Long
Public Const GWL_WNDPROC = (-4)
Public Const WM_HOTKEY = &H312
Public Const MOD_CONTROL = &H2
Public Const MOD_ALT = &H1
Public Const VK_UP = &H26
Public Const VK_DOWN = &H28
Public preWinProc As Long
Public Function wndproc(ByVal hwnd As Long, ByVal Msg As Long, ByVal wParam As Long, ByVal lParam As Long) As Long
If Msg = WM_HOTKEY Then
Select Case wParam
Case 0
If Form1.WindowsMediaPlayer1.settings.volume < 100 Then Form1.WindowsMediaPlayer1.settings.volume = Form1.WindowsMediaPlayer1.settings.volume + 1
Case 1
If Form1.WindowsMediaPlayer1.settings.volume > 0 Then Form1.WindowsMediaPlayer1.settings.volume = Form1.WindowsMediaPlayer1.settings.volume - 1
End Select
End If
wndproc = CallWindowProc(preWinProc, hwnd, Msg, wParam, lParam)
End Function
’以下保存在窗体中
Private Sub Form_Load()
preWinProc = GetWindowLong(Me.hwnd, GWL_WNDPROC) '获得窗口过程的地址
SetWindowLong Me.hwnd, GWL_WNDPROC, AddressOf wndproc '为窗口过程设定一个新的地址
RegisterHotKey Me.hwnd, 0, MOD_CONTROL + MOD_ALT, VK_UP
RegisterHotKey Me.hwnd, 1, MOD_CONTROL + MOD_ALT, VK_DOWN '登记热键
End Sub
Private Sub Form_Unload(Cancel As Integer)
UnregisterHotKey Me.hwnd, 0
UnregisterHotKey Me.hwnd, 1 '释放先前登记的热键
SetWindowLong Me.hwnd, GWL_WNDPROC, preWinProc '还原窗口过程地址
End Sub
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
'api声明
Private Declare Function GetAsyncKeyState Lib "user32" (ByVal vkey As Long) As Integer '热键
Private Sub Form_Load()
Timer1.Interval=100
Timer1.Enabled = true
End Sub
Private Sub Timer1_Timer()
If GetAsyncKeyState(vbKeyMenu) And GetAsyncKeyState(vbKeyControl) And GetAsyncKeyState(vbKeyUp) Then '按下Ctrl+Alt+↑
If WindowsMediaPlayer1.settings.volume < 100 Then
WindowsMediaPlayer1.settings.volume = WindowsMediaPlayer1.settings.volume + 1
End If
End If
If GetAsyncKeyState(vbKeyMenu) And GetAsyncKeyState(vbKeyControl) And GetAsyncKeyState(vbKeyDown) Then '按下Ctrl+Alt+↓
If WindowsMediaPlayer1.settings.volume > 0 Then
WindowsMediaPlayer1.settings.volume = WindowsMediaPlayer1.settings.volume - 1
End If
End If
End Sub
Private Declare Function GetAsyncKeyState Lib "user32" (ByVal vkey As Long) As Integer '热键
Private Sub Form_Load()
Timer1.Interval=100
Timer1.Enabled = true
End Sub
Private Sub Timer1_Timer()
If GetAsyncKeyState(vbKeyMenu) And GetAsyncKeyState(vbKeyControl) And GetAsyncKeyState(vbKeyUp) Then '按下Ctrl+Alt+↑
If WindowsMediaPlayer1.settings.volume < 100 Then
WindowsMediaPlayer1.settings.volume = WindowsMediaPlayer1.settings.volume + 1
End If
End If
If GetAsyncKeyState(vbKeyMenu) And GetAsyncKeyState(vbKeyControl) And GetAsyncKeyState(vbKeyDown) Then '按下Ctrl+Alt+↓
If WindowsMediaPlayer1.settings.volume > 0 Then
WindowsMediaPlayer1.settings.volume = WindowsMediaPlayer1.settings.volume - 1
End If
End If
End Sub
本回答被提问者采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
NO
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询