用vb写一个禁止f12使用的小程序!高分!!!!

用vb写一个禁止f12使用的小程序、只要程序使用、那么F12就无法使用、怎么弄、谁会呀、高分我不要禁止键盘的、给我这个没用。。我只要禁止F12的、把源代码给我、我粘一下能... 用vb写一个禁止f12使用的小程序、只要程序使用、那么F12 就无法使用、怎么弄、谁会呀、高分
我不要禁止键盘的、给我这个没用。。我只要禁止F12的、把源代码给我、我粘一下能使用就ok。不要禁止全键盘的
展开
 我来答
bater2000
2011-11-16 · TA获得超过1486个赞
知道小有建树答主
回答量:803
采纳率:0%
帮助的人:1078万
展开全部
无论用VB、Delphi、甚至VC++这个功能都得调用操作系统的Win API函数Hook来实现。
方法是用Hook来勾住系统捕捉到的键盘事件,当发现用户按下的是F12时阻止键盘消息传递来实现F12不响应的。

以下钩子程序能阻止除ctrl alt del以外的所有键盘消息
Option Explicit

Private Declare Function CallNextHookEx Lib "user32 " _
(ByVal hHook As Long, _
ByVal nCode As Long, _
ByVal wParam As Long, _
lParam As Any) As Long

Private 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

Private Declare Function UnhookWindowsHookEx Lib "user32 " _
(ByVal hHook As Long) As Long

Private Declare Sub CopyMemory Lib "kernel32 " _
Alias "RtlMoveMemory " _
(Destination As Any, _
Source As Any, _
ByVal Length As Long)

Private Type PKBDLLHOOKSTRUCT
vkCode As Long
scanCode As Long
flags As Long
time As Long
dwExtraInfo As Long
End Type

Private Const WM_KEYDOWN = &H100
Private Const WM_SYSKEYDOWN = &H104
Private Const WM_KEYUP = &H101
Private Const WM_SYSKEYUP = &H105

Private Const VK_LWIN = &H5B
Private Const VK_RWIN = &H5C

Private Const HC_ACTION = 0
Private Const WH_KEYBOARD_LL = 13

Private lngHook As Long

'使用底层KeyboardHook拦截按键消息
Public Function LowLevelKeyboardProc(ByVal nCode As Long, _
ByVal wParam As Long, _
ByVal lParam As Long) As Long
Dim blnHook As Boolean
Dim p As PKBDLLHOOKSTRUCT

If nCode = HC_ACTION Then
Select Case wParam
Case WM_KEYDOWN, WM_SYSKEYDOWN, WM_KEYUP, WM_SYSKEYUP
Call CopyMemory(p, ByVal lParam, Len(p))
If p.vkCode = VK_LWIN Or p.vkCode = VK_RWIN Then '按下了左/右Win键
blnHook = True
End If
Case Else
'do nothing
End Select
End If

If blnHook Then
LowLevelKeyboardProc = 1
Else
Call CallNextHookEx(WH_KEYBOARD_LL, nCode, wParam, lParam)
End If
End Function

Public Sub HooK()
lngHook = SetWindowsHookEx(WH_KEYBOARD_LL, _
AddressOf LowLevelKeyboardProc, _
App.hInstance, _
0)
End Sub

Public Sub UnHooK()
Call UnhookWindowsHookEx(lngHook)
End Sub

'***************************
'把以下程序粘贴到窗体中
'***************************
Private Sub Form_Load()
Hook
End Sub

Private Sub Form_Unload(Cancel As Integer)
UnHook
End Sub
最美乡村行
2011-11-18 · TA获得超过1136个赞
知道大有可为答主
回答量:1191
采纳率:0%
帮助的人:1640万
展开全部
form里
---------------------------------------------
Private Sub Command1_Click()
Unload Me
End Sub

'程序启动时注册功能热键F12
Private Sub Form_Load()
Dim Modifiers As Long, aa As Long
preWinProc = GetWindowLong(Me.hWnd, GWL_WNDPROC)
SetWindowLong Me.hWnd, GWL_WNDPROC, AddressOf WndProc
'uVirtKey = vbKeyF11
F12 = vbKeyF12
' RegisterHotKey Me.hWnd, 1, 0, uVirtKey
RegisterHotKey Me.hWnd, 2, 0, F12

End Sub

'当程序被关闭时,取消已经注册的热键
Private Sub Form_Unload(Cancel As Integer)
SetWindowLong Me.hWnd, GWL_WNDPROC, preWinProc
UnregisterHotKey Me.hWnd, uVirtKey '取消系统级热键,释放资源
'End '终止程序运行
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 fsModifiers As Long, ByVal vk As Long) As Long
'取消热键并释放占用的资源
Public Declare Function UnregisterHotKey Lib "user32" (ByVal hWnd As Long, ByVal ID As Long) As Long
'上述五个API函数是注册系统级热键所必需的,具体实现过程如后文所示
Private Declare Sub Sleep Lib "kernel32" (ByVal dwMilliseconds As Long)
Private Declare Function MapVirtualKey Lib "user32" Alias "MapVirtualKeyA" (ByVal wCode As Long, ByVal wMapType As Long) As Long
Private Declare Sub keybd_event Lib "user32" (ByVal bVk As Byte, ByVal bScan As Byte, ByVal dwFlags As Long, ByVal dwExtraInfo As Long)
Const KEYEVENTF_KEYUP = &H2
Const VK_LWIN = &H5B

'热键标志常数,用来判断当键盘按键被按下时是否命中了我们设定的热键
Public Const WM_HOTKEY = &H312
Public Const GWL_WNDPROC = (-4)

'定义系统的热键,原中断标示,被隐藏的项目句柄
Public preWinProc As Long, MyhWnd As Long, uVirtKey As Long, F12 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 '如果拦截到热键标志常数
If wParam = 2 Then
'MsgBox "F12"
End If
Else
'如果不是热键,或者不是我们设置的热键,交还控制权给系统,继续监测热键
WndProc = CallWindowProc(preWinProc, hWnd, Msg, wParam, lParam)

End If
End Function
本回答被提问者采纳
已赞过 已踩过<
你对这个回答的评价是?
评论 收起
推荐律师服务: 若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询

为你推荐:

下载百度知道APP,抢鲜体验
使用百度知道APP,立即抢鲜体验。你的手机镜头里或许有别人想知道的答案。
扫描二维码下载
×

类别

我们会通过消息、邮箱等方式尽快将举报结果通知您。

说明

0/200

提交
取消

辅 助

模 式