设为首页收藏本站Access中国

Office中国论坛/Access中国论坛

 找回密码
 注册

QQ登录

只需一步,快速开始

返回列表 发新帖
查看: 2342|回复: 5
打印 上一主题 下一主题

[模块/函数] 请教!如何在打开窗体后屏蔽所有键盘操作啊?

[复制链接]
跳转到指定楼层
1#
发表于 2012-11-2 00:24:53 | 只看该作者 回帖奖励 |倒序浏览 |阅读模式
本帖最后由 sxgaobo 于 2012-11-2 22:51 编辑

想达到这样的目的:
打开窗体后屏蔽键盘所有键,关闭窗体后在释放。
分享到:  QQ好友和群QQ好友和群 QQ空间QQ空间 腾讯微博腾讯微博 腾讯朋友腾讯朋友
收藏收藏 分享分享 分享淘帖 订阅订阅

点击这里给我发消息

2#
发表于 2012-11-2 09:40:35 | 只看该作者
实在不好意思,因为没有办法,恢复22号的数据,所以这几天的数据都丢失了。
在keypress或keydown里 筛选所有的击键 都返回 0, 不处理
3#
 楼主| 发表于 2012-11-2 23:02:36 | 只看该作者
谢谢站长的关注!
我试了,屏蔽不了打开开始菜单的那个快捷键,就是有WINDOWS标志的那键,键值是91,我设置了keydown=91时返回0,可还是能打开开始菜单。我想要的结果是打开窗体后,按键盘的任何键都不起作用,只能用鼠标操作,关闭窗体后释放对键盘的屏蔽。麻烦您给看看好吗!
4#
 楼主| 发表于 2012-11-8 18:46:05 | 只看该作者
自己顶顶!!!

点击这里给我发消息

5#
发表于 2012-11-8 22:00:09 | 只看该作者
可能要用钩子,试试这个


Option Explicit

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 UnhookWindowsHookEx Lib "user32" (ByVal hHook 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 Sub CopyMemory Lib "kernel32" Alias "RtlMoveMemory" (lpvDest As Any, ByVal lpvSource As Long, ByVal cbCopy As Long)
Public Declare Function GetKeyState Lib "user32" (ByVal nVirtKey As Long) As Integer
Public Type KEYMSGS
        vKey As Long
        sKey As Long
        flag As Long
        time As Long
End Type
Public Const WH_KEYBOARD_LL = 13
Public Const VK_LWIN = &H5B
Public Const VK_RWIN = &H5C
Public Const VK_CONTROL = &H11
Public Const VK_SHIFT = &H10
Public Const HC_ACTION = 0
Public Const HC_SYSMODALOFF = 5
Public Const HC_SYSMODALON = 4
Public Const WM_KEYDOWN = &H100
Public Const WM_KEYUP = &H101
Public Const WM_SYSKEYDOWN = &H104
Public Const WM_SYSKEYUP = &H105

Public P As KEYMSGS
Public lHook As Long

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)
             Select Case P.vKey
             Case VK_LWIN, VK_RWIN           'Èç¹û°´ÁËWIN¼ü
                 fEatKeystroke = True        '¾Í³ÔÁË
             End Select
         End If
     End If
     If fEatKeystroke Then
         LowLevelKeyboardProc = -1
     Else
         LowLevelKeyboardProc = CallNextHookEx(0, nCode, wParam, ByVal lParam)
     End If
End Function


'Private Sub AddHook()
'     lHook = SetWindowsHookEx(WH_KEYBOARD_LL, AddressOf LowLevelKeyboardProc, Me.hWnd, 0)  'Application.hWndAccessApp
' End Sub
'
'Private Sub DelHook()
'     UnhookWindowsHookEx lHook
' End Sub
6#
发表于 2012-11-8 23:06:58 | 只看该作者
用键盘钩子  应该可以
您需要登录后才可以回帖 登录 | 注册

本版积分规则

QQ|站长邮箱|小黑屋|手机版|Office中国/Access中国 ( 粤ICP备10043721号-1 )  

GMT+8, 2024-11-15 22:22 , Processed in 0.134130 second(s), 30 queries .

Powered by Discuz! X3.3

© 2001-2017 Comsenz Inc.

快速回复 返回顶部 返回列表