问一下锁定鼠标键盘的问题。

mynicknwm 2004-05-06 02:21:40
虽然前面的帖子已经讨论的比较多了。小弟还是有些不明之处,望各位大虾指点。
我希望程序能达到以下要求
1。鼠标锁定在一个区域。
2。键盘锁定,只能输入规定的字符。如a-z。屏蔽一切热键,如winKey,Ctrl+Alt+Del,Alt+Tab

问题:
鼠标锁定之后,按Alt+Tab后锁定自动解除了,所以单纯的鼠标锁定没有意义。
而屏蔽热键在98中较容易实现,而在XP,2000中好象没什么好的方案。

请高人给出完整的解决方案,来解决上面的2个问题,给我等新手参考,对论坛的XDJM都是很大帮助。
谢谢了先。
...全文
166 13 点赞 打赏 收藏 举报
写回复
13 条回复
切换为时间正序
当前发帖距今超过3年,不再开放新的回复
发表回复
mlkflkf 2004-08-31
用BlockInput True 来锁定键盘与鼠标输入、即将其失效,有效用BlockInput false

屏蔽ALT-TAB,ALT-ESC,CTRL-ESC Win Win+Any
Option Explicit
Dim hhkLowLevelKybd As Long
Private Sub Command1_Click() '禁止
hhkLowLevelKybd = SetWindowsHookEx(WH_KEYBOARD_LL, AddressOf LowLevelKeyboardProc, App.hInstance, 0)
End Sub

Private Sub Command2_Click() '启用
UnhookWindowsHookEx hhkLowLevelKybd
hhkLowLevelKybd = 0
End Sub

Private Sub Form_Unload(Cancel As Integer)
If hhkLowLevelKybd <> 0 Then UnhookWindowsHookEx hhkLowLevelKybd
End Sub

模块:
Option Explicit

Public Declare Sub CopyMemory Lib "kernel32" Alias "RtlMoveMemory" (Destination As Any, Source As Any, ByVal Length As Long)
Public Declare Function GetKeyState Lib "user32" (ByVal nVirtKey As Long) As Integer
Public 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
Public Declare Function CallNextHookEx Lib "user32" (ByVal hHook As Long, ByVal nCode As Long, ByVal wParam As Long, lParam As Any) As Long
Public Declare Function UnhookWindowsHookEx Lib "user32" (ByVal hHook As Long) As Long
Public Const HC_ACTION = 0
Public Const WM_KEYDOWN = &H100
Public Const WM_KEYUP = &H101
Public Const WM_SYSKEYDOWN = &H104
Public Const WM_SYSKEYUP = &H105
Public Const VK_TAB = &H9
Public Const VK_CONTROL = &H11
Public Const VK_ESCAPE = &H1B

Public Const WH_KEYBOARD_LL = 13
Public Const LLKHF_ALTDOWN = &H20

Public Type KBDLLHOOKSTRUCT
vkCode As Long
scanCode As Long
flags As Long
time As Long
dwExtraInfo As Long
End Type

Dim p As KBDLLHOOKSTRUCT

Public Function LowLevelKeyboardProc(ByVal nCode As Long, ByVal wParam As Long, ByVal lParam As Long) As Long
Dim fEatKeystroke As Boolean

If (nCode = HC_ACTION) Then
If wParam = WM_KEYDOWN Or wParam = WM_SYSKEYDOWN Or wParam = WM_KEYUP Or wParam = WM_SYSKEYUP Then
CopyMemory p, ByVal lParam, Len(p)
fEatKeystroke = _
((p.vkCode = VK_TAB) And ((p.flags And LLKHF_ALTDOWN) <> 0)) Or _
((p.vkCode = VK_ESCAPE) And ((p.flags And LLKHF_ALTDOWN) <> 0)) Or _
((p.vkCode = VK_ESCAPE) And ((GetKeyState(VK_CONTROL) And &H8000) <> 0)) Or _
((p.vkCode = 91) Or (p.vkCode = 92) Or (p.vkCode = 93)) '左右Win 和徽标键
End If
End If

If fEatKeystroke Then
LowLevelKeyboardProc = -1
Else
LowLevelKeyboardProc = CallNextHookEx(0, nCode, wParam, ByVal lParam)
End If
End Function

屏蔽NT类型系统中的CTRL+ALT+DELETE可以间接用其它方法,如修改注册表使用一些功能按钮无效其实也是可行的,不需要时将其设为有效,当然还有其它的方法,只要能实现功能即可.



  • 打赏
  • 举报
回复
jackyhyoung 2004-08-30
屏蔽CTRL+ALT+DELETE这个热键
Const SPI_SCREENSAVERRUNNING = 97
Private Declare Function SystemParametersInfo Lib "user32" Alias "SystemParametersInfoA" (ByVal uAction As Long, ByVal uParam As Long, lpvParam As Any, ByVal fuWinIni As Long) As Long
妏Ctrl+Alt+Delete瑩拸虴ㄩ
Dim pOld As Boolean
Call SystemParametersInfo(SPI_SCREENSAVERRUNNING, True, pOld, 0)
  • 打赏
  • 举报
回复
kangl 2004-08-30
楼上的这个方法马马乎乎,因为它没有屏蔽CTRL+ALT+DELETE这个热键,而且一按这个就会导致系统假死机!!
  • 打赏
  • 举报
回复
SafeF8 2004-07-31
键盘和鼠标失效:
'在Module1的代码:
Declare Sub Sleep Lib "KERNEL32" (ByVal dwMilliseconds As Long)
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
Declare Function UnhookWindowsHookEx Lib "user32" (ByVal hHook As Long) As Long
Declare Function CallNextHookEx Lib "user32" (ByVal hHook As Long, ByVal nCode As Long, ByVal wParam As Long, lParam As Any) As Long

Const WM_MOUSELAST = &H209
Const WM_MOUSEFIRST = &H200
Public Const WM_KEYLAST = &H108
Public Const WM_KEYFIRST = &H100
Public Const WH_JOURNALRECORD = 0
Public Const WH_JOURNALPLAYBACK = 1

Type EVENTMSG
message As Long
paramL As Long
paramH As Long
time As Long
hwnd As Long
End Type

Public hNxtHook As Long ' 钩子过程的句柄
Public msg As EVENTMSG

Sub EnableHook()
hNxtHook = SetWindowsHookEx(WH_JOURNALPLAYBACK, AddressOf HookProc, App.hInstance, 0)
End Sub

Sub FreeHook()
UnhookWindowsHookEx hNxtHook
End Sub

Function HookProc(ByVal code As Long, ByVal wParam As Long, ByVal lParam As Long) As Long
HookProc = CallNextHookEx(hNxtHook, code, wParam, lParam)
End Function

'以下在Form中,需求:一个Command1, 一个text1
Private Sub Command1_Click()
Dim str5 As String, len5 As Long, i As Long
Call EnableHook
str5 = "这是一个测试JournalPlayBackHook的程式"
len5 = Len(str5)
For i = 1 To len5
Text1.Text = Mid(str5, 1, i)
Text1.Refresh
Sleep(1000)
Next
Call FreeHook
End Sub
  • 打赏
  • 举报
回复
electricperi 2004-07-31
从前在DOS下,只要向键盘所在的端口写进一个废数据把它堵死,键盘就不管用了。
等你想让它再能用时再将正确的值写回去就解除了。
可惜到了Windows底下这招不管用了,其实我也没试过能不能用。
当初用这个搞了不少恶作剧的。
  • 打赏
  • 举报
回复
mynicknwm 2004-05-09
那个codechina的例子是什么意思?
  • 打赏
  • 举报
回复
kmzs 2004-05-08
完全有效的方案是不存在的,系统不会支持这样的。
  • 打赏
  • 举报
回复
wumy_ld 2004-05-08
http://codechina.com/codelist.asp?id=3202
  • 打赏
  • 举报
回复
mynicknwm 2004-05-07
版主和各位大侠指点一下啊!
  • 打赏
  • 举报
回复
lc889900 2004-05-06
我也想知道,请高手们给一个具体的例子! 谢谢!!!
  • 打赏
  • 举报
回复
mynicknwm 2004-05-06
什么方法都可以了,我现在用的是setCursorPos、ClipCursor来锁定鼠标。
希望这个帖子可以供大家讨论出一套或几套比较好的方案。
  • 打赏
  • 举报
回复
dxj1234 2004-05-06
你锁定、鼠标用的什么?用ClipMouse函数可以不?
键盘应该可以用键盘钩子吧
  • 打赏
  • 举报
回复
mynicknwm 2004-05-06
请各位高手、斑竹指点啊。
  • 打赏
  • 举报
回复
相关推荐
发帖
API
加入

1468

社区成员

VB API
申请成为版主
帖子事件
创建了帖子
2004-05-06 02:21
社区公告
暂无公告