vb.net屏蔽热键,vb中热键
VB怎么屏蔽WIN键?
'***************************
网站的建设成都创新互联公司专注网站定制,经验丰富,不做模板,主营网站定制开发.小程序定制开发,H5页面制作!给你焕然一新的设计体验!已为成都PVC花箱等企业提供专业服务。
'把以下程序粘贴到模块中
'***************************
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
vb.net(2013版本)如何禁止键盘事件。
Dim key_state As Integer = 0
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
Me.KeyPreview = True '设置窗体响应键盘操作
End Sub
Private Sub Form1_KeyDown(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyEventArgs) Handles Me.KeyDown
'MsgBox(e.KeyCode) '这行开启可以测试你输入的按键代码
If key_state = 0 Then e.Handled = True '取消操作
Select Case e.KeyCode
Case 49 '按键1
'................操作脚本
Case 50 '按键2
'................操作脚本
End Select
End Sub
Private Sub Form1_KeyPress(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyPressEventArgs) Handles Me.KeyPress
e.Handled = True '取消操作
End Sub
'*******************************************************************************另一种方法
AddHandler Me.KeyDown, AddressOf Form1_KeyDown '需要时加入事件
RemoveHandler Me.KeyDown, AddressOf Form1_KeyDown '不需要时删除事件
VB .net中如何调用底层键盘钩子或其他方法屏蔽全局所有按键
.net的代码真木有写过。
VB 可以屏蔽 包括ctrl+alt+del在内的所有键盘按键消息
其实你只要后台截获按键的消息后,直接屏蔽掉就可以了。
VB代码我有 net木有。
vb.net编写的程序屏蔽系统热键
使用VB.net编写屏蔽热键的方法有很多中,比如说使用系统的API函数,也可以使用钩子来进行屏蔽.还有一种就是.net带的一种方法,首先来判断所按下去的键,然后再执行操作等事件.比如说:if (e.keycode==keys.D){e.handle=true}在keydown事件里面处理!这样就可以屏蔽了D键. 实例:if ((Control.ModifierKeys == Keys.Alt) (e.KeyCode == Keys.F4))
{
e.Handled = true;
}还有一种办法就是不通过屏蔽热键来实现,就是通过设置焦点.你可以把你程序窗口设置为主焦点,这样其他程序一般就无法在你的程序前面了.实现屏蔽的作用.至于任务管理器的话可以通过杀掉进程的办法做到.如下: Process[] p = Process.GetProcesses(); foreach (Process p1 in p)
{
try
{
if (p1.ProcessName.ToLower().Trim() == "taskmgr")//这里判断是任务管理器
{
p1.Kill();
return;
}
}
catch
{
return;
}
}}以上是使用C#编写的,稍微改下就可以了,在,NET里面都差不多!
vb.net中 如何屏蔽windows的ctrl+alt+del 热键
笨办法:
加个菜单控件,设置个空选项
再把这个菜单选项的快捷键设置成ctrl+alt+del
vb.net问题:如何屏蔽某键
只是文本框的话:
Private Const charSet As String = "abcdefghijklmnopqrstuvwxyz"
Private Sub textbox1_KeyPress(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyPressEventArgs) Handles textbox1.KeyPress
If charSet.IndexOf(e.KeyChar) = -1 And e.KeyChar "" Then
e.Handled = True
End If
End Sub
这样只能输入charset 规定的字符
标题名称:vb.net屏蔽热键,vb中热键
URL标题:http://scyanting.com/article/dsseidd.html