VB鎖定鍵盤 滑鼠

2021-08-30 23:36:34 字數 2249 閱讀 9803

一、鎖定鍵盤

1.新增模組

module1

將以下**複製到module1

public hhook as long

public h_hook as long

declare function unhookwindowshookex lib "user32" (byval hhook as long) 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 callnexthookex lib "user32" (byval hhook as long, byval ncode as long, byval wparam as long, lparam as long) 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 const wh_keyboard_ll = 13

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

2.在form_load中新增以下**,實現鍵盤鎖定

private sub form_load()

end sub

3.在form_unload中新增以下**,實現視窗關閉後解開鍵盤

private sub form_unload(cancel as integer)

call unhookwindowshookex(hhook)

end sub

二、滑鼠鎖定

option explicit

private declare function getwindowrect lib "user32" (byval hwnd as long, lprect as rect) as long

private declare function clipcursor lib "user32" (lprect as any) as long

private declare function setcursorpos lib "user32" (byval x as long, byval y as long) as long

private type rect

left as long

top as long

right as long

bottom as long

end type

private sub command1_click() '鎖定滑鼠

dim r as rect

r.left = 100: r.top = 100

r.right = 100: r.bottom = 100

clipcursor r

end sub

'private sub command2_click() '解除鎖定

'clipcursor byval 0&

'end sub

private sub form_dblclick() '解除鎖定

clipcursor byval 0&

end sub

鍵盤上的滾動鎖定鍵

今天心情非常不好,工作用的鍵盤又出么蛾子。雙顯示器,乙個滑鼠,乙個鍵盤,然後發現鍵盤只能在乙個顯示器上正常使用,另外乙個顯示器上失效了,真是事上加事。檢視了一下鍵盤,發現鍵盤上亮了乙個不常用的燈,就是小鍵盤上面有三個燈,乙個是小鍵盤的控制燈,乙個是大寫開啟的燈,另外的那個就是之前從來沒有使用過,但是...

使用鉤子如何鎖定鍵盤的方法分享

複製 如下 include include 處理按鍵訊息的過程函式 中使用鉤子而無dll的關鍵就在於getmodulehandle null getmodulehandle 引數為nu得到的是呼叫者本身的模組控制代碼,也就是說用程式本身作為dll。因為是console程式,所以隨著程式的結束鉤子也就...

VB 全域性鍵盤 滑鼠鉤子

if code hc action then copymemory mousemsg,lparam,lenb mousemsg form1.txtmsg 1 text x str mousemsg.x y str mousemsg.y form1.txthwnd 1 format wparam,0 ...