VB 全域性Hook滑鼠訊息

2021-08-27 04:38:02 字數 2142 閱讀 2354

vb 全域性hook滑鼠鉤子,獲取滑鼠單擊左鍵、滑鼠座標位置等。

以下是滑鼠的按鍵訊息: 鍵

按下釋放

按下(雙擊)

左wm_nclbuttondown=&ha1

wm_nclbuttonup=&ha2

wm_nclbuttondblclk=&ha3

中wm_ncmbuttondown=&ha7

wm_ncmbuttonup=&ha8

wm_ncmbuttondblclk=&ha9

右wm_ncrbuttondown=&ha4

wm_ncrbuttonup=&ha5

wm_ncrbuttondblclk=&ha6

form**如下:

option explicit

private sub form_load()

hook

end sub

private sub form_unload(cancel as integer)

unhook

end sub

module**:

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 pointapi

x as long

y as long

end type

private type msllhookstruct

pt as pointapi

mousedata as long

flags as long

time as long

dwextrainfo as long

end type

private const wm_lbuttonup = &h202

private const wh_mouse_ll = 14

private hhook as long

public function mousehook(byval ncode as long, _

byval wparam as long, _

byval lparam as long) as long

dim mhs as msllhookstruct, pt as pointapi

if wparam = wm_lbuttonup then

call copymemory(mhs, byval lparam, lenb(mhs))

pt = mhs.pt

call copymemory(p, byval lparam, len(p))

debug.print "左鍵單擊    座標:" & pt.x & "  "; pt.y

end if

call callnexthookex(hhook, ncode, wparam, lparam)

end function

public sub unhook()

call unhookwindowshookex(hhook)

end sub

C 全域性滑鼠鍵盤Hook

原文出自 using system using system.collections.generic using system.reflection using system.runtime.interopservices using system.text using system.windows...

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 ...

C 全域性滑鼠鍵盤Hook 備查

using system using system.collections.generic using system.reflection using system.runtime.interopservices using system.text using system.windows.form...