VBGood網站全文搜索 Google

搜索VBGood全站網頁(全文搜索)

VB愛好者樂園(VBGood)

 找回密碼
 立即注冊
搜索
查看: 680|回復: 1
打印 上一主題 下一主題

[求助] vb屏蔽鍵盤操作的模塊中如何排除空格鍵

[復制鏈接]
跳轉到指定樓層
1
發表于 2018-8-22 13:09:16 | 只看該作者 回帖獎勵 |倒序瀏覽 |閱讀模式
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
'idHook參數代表攔截的類型,主要有鍵盤、鼠標等(當攔截鍵盤輸入時值為2)
'lpfn參數代表Hook函數的位址
'hmod代表.dll的hInstance
'dwThreadId代表執行攔截的ThreadId
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
Public Const WH_KEYBOARD = 2
Public Const WH_KEYBOARD_LL = 13
Public Const WH_SHELL = 10
Public Const WH_GETMESSAGE = 3
Public Const WH_CALLWNDPROC = 4
Public h_Hook As Long
Public Const WM_LBUTTONDOWN = &H201
Public Const WM_LBUTTONUP = &H202
Public Const WM_RBUTTONDOWN = &H204
Public Const WM_RBUTTONUP As Long = &H205
Public hHook As Long
Public Declare Sub CopyMemory Lib "kernel32" Alias "RtlMoveMemory" (Destination As Any, Source As Any, ByVal Length As Long)
Type tagKBDLLHOOKSTRUCT
    vkCode       As Integer          '// virtual key code
    scanCode     As Integer        '// scan code
    flags        As Long   '// flags
    Time         As Long    '// time stamp for this message
    dwExtraInfo  As Long '// extra info from the driver or keybd_event
End Type
Public Declare Function GetKeyboardState Lib "user32" (pbKeyState As Byte) As Long

Sub EnableHook() '定義EnableHook
'設置攔截
    hHook = SetWindowsHookEx(WH_KEYBOARD_LL, AddressOf Myfunc, App.hInstance, 0)
End Sub

Sub DisableHook() '定義DisableHook
    Dim ret As Long
    ret = UnhookWindowsHookEx(hHook) '取消攔截
End Sub

Function Myfunc(ByVal ncode As Long, ByVal wParam As Long, ByVal lParam As Long) As Long 'wParam代表按鍵
    'On Error Resume Next
Dim kk As tagKBDLLHOOKSTRUCT
Dim kb As Long, pks As Byte
    'Debug.Print wParam
    CopyMemory kk, lParam, Len(kk)
    'If wParam = 256 Then
    Myfunc = 1: Exit Function
    'endif
    Myfunc = CallNextHookEx(hHook, ncode, wParam, lParam) '傳到下一個攔截
End Function

Public Function MyKBHook(ByVal ncode As Long, ByVal wParam As Long, ByVal lParam As Long) As Long
If ncode = 0 Then
MyKBHook = 1
End If
End Function

Public Function My_KBHook(ByVal ncode As Long, ByVal wParam As Long, ByVal lParam As Long) As Long
If ncode = 0 Then
If wParam = WM_MOUSEMOVE Then
My_KBHook = CallNextHookEx(h_Hook, ncode, wParam, lParam)
Else
My_KBHook = 1
End If
End If
End Function

請教一下,此模塊中如何排除屏蔽空格按鍵?

點評

海!外直播 t.cn/RxlBLRP 禁聞視頻 t.cn/RJvO78o 看了那個中國雙胞胎棄嬰被美國人分別收養后機緣巧合重逢的視頻,感動了一會兒.然后就想,中國的對外貿易,最成功的可能就是賣孩子,第二個是租熊貓,第三個我想了半天,楞   發表于 2018-10-8 20:22
您需要登錄后才可以回帖 登錄 | 立即注冊

本版積分規則

文字版|手機版|小黑屋|VBGood  

GMT+8, 2019-12-7 23:02

VB愛好者樂園(VBGood)
快速回復 返回頂部 返回列表
快乐十分开奖结查询