求助高手,请问,?怎样吧下面VB程序改成支持系统热键?
PrivateSubForm_KeyPress(KeyAsciiAsInteger)IfKeyAscii=48Then''按下数字0,执行视频的动作1double_Cli...
Private Sub Form_KeyPress(KeyAscii As Integer)
If KeyAscii = 48 Then ''按下数字0,执行视频的动作1
double_Click
Me.SetFocus
End If
If KeyAscii = 49 Then ''按下数字1,执行视频的动作2
back_Click
Me.SetFocus
End If
If KeyAscii = 50 Then ''按下数字2,执行 声卡
soundcard_Click
Me.SetFocus
End If
End Sub 展开
If KeyAscii = 48 Then ''按下数字0,执行视频的动作1
double_Click
Me.SetFocus
End If
If KeyAscii = 49 Then ''按下数字1,执行视频的动作2
back_Click
Me.SetFocus
End If
If KeyAscii = 50 Then ''按下数字2,执行 声卡
soundcard_Click
Me.SetFocus
End If
End Sub 展开
1个回答
展开全部
Declare Function RegisterHotKey Lib "user32" (ByVal hwnd As Long, ByVal id As Long, ByVal fsModifiers As Long, ByVal vk As Long) As Long
Declare Function UnregisterHotKey Lib "user32" (ByVal hwnd As Long, ByVal id As Long) As Long
Declare Function SetWindowLong Lib "user32" Alias "SetWindowLongA" (ByVal hwnd As Long, ByVal nIndex As Long, ByVal dwNewLong As Long) As Long
Declare Function GetWindowLong Lib "user32" Alias "GetWindowLongA" (ByVal hwnd As Long, ByVal nIndex As Long) As Long
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 Const WM_HOTKEY = &H312
Public Const MOD_ALT = &H1
Public Const MOD_CONTROL = &H2
Public Const MOD_SHIFT = &H4
Public Const GWL_WNDPROC = (-4)
Public preWinProc As Long
Public Modifiers As Long, uVirtKey As Long, idHotKey As Long
Private Type taLong
ll As Long
End Type
Private Type t2Int
lWord As Integer
hword As Integer
End Type
Public mAddr As String
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
If wParam = idHotKey Then
Dim lp As taLong
Dim i2 As t2Int
lp.ll = lParam
LSet i2 = lp
If (i2.lWord = Modifiers) And i2.hword = uVirtKey Then
surfForm.Visible = True
End If
End If
End If
wndproc = CallWindowProc(preWinProc, hwnd, Msg, wParam, lParam)
End Function
Dim ret As Long
idHotKey = 1
Modifiers = MOD_ALT + MOD_CONTROL
uVirtKey = vbKey3
preWinProc = GetWindowLong(Me.hwnd, GWL_WNDPROC)
ret = SetWindowLong(Me.hwnd, GWL_WNDPROC, AddressOf wndproc)
ret = RegisterHotKey(Me.hwnd, idHotKey, Modifiers, uVirtKey)
If ret <> 1 Then
MsgBox "热键设置失败!"
End If
Declare Function UnregisterHotKey Lib "user32" (ByVal hwnd As Long, ByVal id As Long) As Long
Declare Function SetWindowLong Lib "user32" Alias "SetWindowLongA" (ByVal hwnd As Long, ByVal nIndex As Long, ByVal dwNewLong As Long) As Long
Declare Function GetWindowLong Lib "user32" Alias "GetWindowLongA" (ByVal hwnd As Long, ByVal nIndex As Long) As Long
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 Const WM_HOTKEY = &H312
Public Const MOD_ALT = &H1
Public Const MOD_CONTROL = &H2
Public Const MOD_SHIFT = &H4
Public Const GWL_WNDPROC = (-4)
Public preWinProc As Long
Public Modifiers As Long, uVirtKey As Long, idHotKey As Long
Private Type taLong
ll As Long
End Type
Private Type t2Int
lWord As Integer
hword As Integer
End Type
Public mAddr As String
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
If wParam = idHotKey Then
Dim lp As taLong
Dim i2 As t2Int
lp.ll = lParam
LSet i2 = lp
If (i2.lWord = Modifiers) And i2.hword = uVirtKey Then
surfForm.Visible = True
End If
End If
End If
wndproc = CallWindowProc(preWinProc, hwnd, Msg, wParam, lParam)
End Function
Dim ret As Long
idHotKey = 1
Modifiers = MOD_ALT + MOD_CONTROL
uVirtKey = vbKey3
preWinProc = GetWindowLong(Me.hwnd, GWL_WNDPROC)
ret = SetWindowLong(Me.hwnd, GWL_WNDPROC, AddressOf wndproc)
ret = RegisterHotKey(Me.hwnd, idHotKey, Modifiers, uVirtKey)
If ret <> 1 Then
MsgBox "热键设置失败!"
End If
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询