怎么测试到键盘的多媒体键(如上网键、我的电脑、音量+、音量-,睡眠键、电源键等等
本帖最后由 goodboy_ttp2011 于 2011-12-10 20:28:56 编辑 小弟刚刚学习VB,现在公司需要做一款多媒体键盘的测试程序。但是小弟做了一款程序,只能测试107个普通按键啊,其他的多媒体按键测试不了。找到一款前辈写的程序,用的他自己做的 *.dll,但是有很多多媒体按键测试不出来,而且按下WIN键时,还会弹出“开始菜单”,按下“上网键”时也会弹出网页,测试时很不方面。
哪位大哥能帮帮小弟。要能够测试键盘的所有普通按键、WIN键、多媒体键,而不会弹出对话框、网页等选项的。下面是我的VB代码,请各位大哥帮帮改改,谢谢!!
form1里面的代码:
Option Explicit
Const LEFT_BUTTON = 1
Const RIGHT_BUTTON = 2
Const MIDDLE_BUTTON = 4
Const RED = &HFF
Const NORMAL = &H80000005
Private Sub Form_Load()
On Error Resume Next
' 本 KeyboardHook_HookProc ㄧ计
SetKeyboardHook Me.hwnd, WM_USER
If Err.Number <> 0 Then
MsgBox "非 KeybHook.dll 定义之 Windows键", vbCritical
End
End If
On Error GoTo 0
' 本跌怠祘
prevWndProc = GetWindowLong(Me.hwnd, GWL_WNDPROC)
SetWindowLong Me.hwnd, GWL_WNDPROC, AddressOf WndProc
Dim pOld As Boolean
' 琵Ctrl+Alt+Del舱龄ア
SystemParametersInfoByRef SPI_SCREENSAVERRUNNING, True, pOld, 0
End Sub
Private Sub Form_Unload(Cancel As Integer)
Dim pOld As Boolean
' 確Ctrl+Alt+Del舱龄
SystemParametersInfoByRef SPI_SCREENSAVERRUNNING, False, pOld, 0
' KeyboardHook_HookProc ㄧ计
ReleaseKeyboardHook
' 跌怠祘
SetWindowLong Me.hwnd, GWL_WNDPROC, prevWndProc
End Sub
Private Sub Label111_Click()
Dim pOld As Boolean
' 確Ctrl+Alt+Del舱龄
SystemParametersInfoByRef SPI_SCREENSAVERRUNNING, False, pOld, 0
Unload Me
End Sub
Option Explicit
Public totalkey As Integer
Public countkey As Integer
Public countk(200) As Integer
Public count1 As Integer
Public count2 As Integer
Public count3 As Integer
Public Const GWL_WNDPROC = (-4)
Public Const WM_USER = &H400
Public Const WM_KEYDOWN = &H100
Public Const WM_KEYUP = &H101
Public Const WM_CHAR = &H102
Public Const WM_SYSKEYDOWN = &H104
Public Const WM_SYSKEYUP = &H105
Public Const WM_SYSCHAR = &H106
Public Const WM_NCHITTEST = &H84
Public Const HTCLIENT = 1
Public Const HTCAPTION = 2
Declare Function SystemParametersInfo Lib "user32" Alias "SystemParametersInfoA" (ByVal uAction As Long, ByVal uParam As Long, ByVal lpvParam As Any, ByVal fuWinIni As Long) As Long
Declare Function SystemParametersInfoByRef Lib "user32" Alias "SystemParametersInfoA" (ByVal uAction As Long, ByVal uParam As Long, lpvParam As Any, ByVal fuWinIni 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
Declare Function GetWindowLong Lib "user32" Alias "GetWindowLongA" (ByVal hwnd As Long, ByVal nIndex 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 SetKeyboardHook Lib "KeybHook" (ByVal hwndPost As Long, ByVal Msg As Long) As Long
Declare Function ReleaseKeyboardHook Lib "KeybHook" () As Long
Declare Function MessageBox Lib "user32" Alias "MessageBoxA" (ByVal hwnd As Long, ByVal lpText As String, ByVal lpCaption As String, ByVal wType As Long) As Long 'msgbox
Public prevWndProc As Long
Function WndProc(ByVal hwnd As Long, ByVal Msg As Long, ByVal wParam As Long, ByVal lParam As Long) As Long
If Msg = WM_USER Then
Form1.List1.AddItem "wParam=" & wParam & ", lParam=" & Hex(lParam)
Form1.List1.ListIndex = Form1.List1.NewIndex
Select Case lParam
Case &H80010201:
Dim pOld As Boolean
' 確Ctrl+Alt+Del舱龄
SystemParametersInfoByRef SPI_SCREENSAVERRUNNING, False, pOld, 0
Unload Form1
End Select
End If
WndProc = CallWindowProc(prevWndProc, hwnd, Msg, wParam, lParam)
End Function
Public Const SPI_GETACCESSTIMEOUT = 60
Public Const SPI_GETANIMATION = 72
Public Const SPI_GETBEEP = 1
Public Const SPI_GETBORDER = 5
Public Const SPI_GETDEFAULTINPUTLANG = 89
Public Const SPI_GETDRAGFULLWINDOWS = 38
Public Const SPI_GETFASTTASKSWITCH = 35
Public Const SPI_GETFILTERKEYS = 50
Public Const SPI_GETFONTSMOOTHING = 74
Public Const SPI_GETGRIDGRANULARITY = 18
Public Const SPI_GETHIGHCONTRAST = 66
Public Const SPI_GETICONMETRICS = 45
Public Const SPI_GETICONTITLELOGFONT = 31
Public Const SPI_GETICONTITLEWRAP = 25
Public Const SPI_GETKEYBOARDDELAY = 22
Public Const SPI_GETKEYBOARDPREF = 68
Public Const SPI_GETKEYBOARDSPEED = 10
Public Const SPI_GETLOWPOWERACTIVE = 83
Public Const SPI_GETLOWPOWERTIMEOUT = 79
Public Const SPI_GETMENUDROPALIGNMENT = 27
Public Const SPI_GETMINIMIZEDMETRICS = 43
Public Const SPI_GETMOUSE = 3
Public Const SPI_GETMOUSEKEYS = 54
Public Const SPI_GETMOUSETRAILS = 94
Public Const SPI_GETNONCLIENTMETRICS = 41
Public Const SPI_GETPOWEROFFACTIVE = 84
Public Const SPI_GETPOWEROFFTIMEOUT = 80
Public Const SPI_GETSCREENREADER = 70
Public Const SPI_GETSCREENSAVEACTIVE = 16
Public Const SPI_GETSCREENSAVETIMEOUT = 14
Public Const SPI_GETSERIALKEYS = 62
Public Const SPI_GETSHOWSOUNDS = 56
Public Const SPI_GETSOUNDSENTRY = 64
Public Const SPI_GETSTICKYKEYS = 58
Public Const SPI_GETTOGGLEKEYS = 52
Public Const SPI_GETWINDOWSEXTENSION = 92
Public Const SPI_GETWORKAREA = 48
Public Const SPI_ICONHORIZONTALSPACING = 13
Public Const SPI_ICONVERTICALSPACING = 24
Public Const SPI_LANGDRIVER = 12
Public Const SPI_SCREENSAVERRUNNING = 97
Public Const SPI_SETACCESSTIMEOUT = 61
Public Const SPI_SETANIMATION = 73
Public Const SPI_SETBEEP = 2
Public Const SPI_SETBORDER = 6
Public Const SPI_SETCURSORS = 87
Public Const SPI_SETDEFAULTINPUTLANG = 90
Public Const SPI_SETDESKPATTERN = 21
Public Const SPI_SETDESKWALLPAPER = 20
Public Const SPI_SETDOUBLECLICKTIME = 32
Public Const SPI_SETDOUBLECLKHEIGHT = 30
Public Const SPI_SETDOUBLECLKWIDTH = 29
Public Const SPI_SETDRAGFULLWINDOWS = 37
Public Const SPI_SETDRAGHEIGHT = 77
Public Const SPI_SETDRAGWIDTH = 76
Public Const SPI_SETFASTTASKSWITCH = 36
Public Const SPI_SETFILTERKEYS = 51
Public Const SPI_SETFONTSMOOTHING = 75
Public Const SPI_SETGRIDGRANULARITY = 19
Public Const SPI_SETHANDHELD = 78
Public Const SPI_SETHIGHCONTRAST = 67
Public Const SPI_SETICONMETRICS = 46
Public Const SPI_SETICONS = 88
Public Const SPI_SETICONTITLELOGFONT = 34
Public Const SPI_SETICONTITLEWRAP = 26
Public Const SPI_SETKEYBOARDDELAY = 23
Public Const SPI_SETKEYBOARDPREF = 69
Public Const SPI_SETKEYBOARDSPEED = 11
Public Const SPI_SETLANGTOGGLE = 91
Public Const SPI_SETLOWPOWERACTIVE = 85
Public Const SPI_SETLOWPOWERTIMEOUT = 81
Public Const SPI_SETMENUDROPALIGNMENT = 28
Public Const SPI_SETMINIMIZEDMETRICS = 44
Public Const SPI_SETMOUSE = 4
Public Const SPI_SETMOUSEBUTTONSWAP = 33
Public Const SPI_SETMOUSEKEYS = 55
Public Const SPI_SETMOUSETRAILS = 93
Public Const SPI_SETNONCLIENTMETRICS = 42
Public Const SPI_SETPENWINDOWS = 49
Public Const SPI_SETPOWEROFFACTIVE = 86
Public Const SPI_SETPOWEROFFTIMEOUT = 82
Public Const SPI_SETSCREENREADER = 71
Public Const SPI_SETSCREENSAVEACTIVE = 17
Public Const SPI_SETSCREENSAVETIMEOUT = 15
Public Const SPI_SETSERIALKEYS = 63
Public Const SPI_SETSHOWSOUNDS = 57
Public Const SPI_SETSOUNDSENTRY = 65
Public Const SPI_SETSTICKYKEYS = 59
Public Const SPI_SETTOGGLEKEYS = 53
Public Const SPI_SETWORKAREA = 47
Public Const SPIF_UPDATEINIFILE = &H1
Public Const SPIF_SENDWININICHANGE = &H2