InPowerS.Net

 找回密碼
 註冊
搜索
查看: 3938|回復: 0

[轉貼]VB 從零開始編外掛(三)

[複製鏈接]
發表於 2008-12-25 21:59:10 | 顯示全部樓層 |閱讀模式
--------------------------------------------------------------------------------------------------------------------------------------------------------
躲避了NP的掃描現在就可以類比了!
--------------------------------------------------------------------------------------------------------------------------------------------------------
需要VB API函數:
keybd_event                             ←函數類比了鍵盤行動
--------------------------------------------------------------------------------------------------------------------------------------------------------
相關API聲明:  
keybd_event

Private Declare Sub keybd_event Lib "user32" (ByVal bVk As Byte, ByVal Scan As Byte, ByVal dwFlags As Long, ByVal dwExtraInfo As Long)
--------------------------------------------------------------------------------------------------------------------------------------------------------
需要的控制項:Timer(interval不為空)
--------------------------------------------------------------------------------------------------------------------------------------------------------
代碼:
Private Declare Sub keybd_event Lib "user32" (ByVal bVk As Byte, ByVal Scan As Byte, ByVal dwFlags As Long, ByVal dwExtraInfo As Long)
Private Sub Timer1_Timer()
Call keybd_event(82, 0, 0, 0) '模擬按下"R"鍵
End Sub
--------------------------------------------------------------------------------------------------------------------------------------------------------
其它模擬:
方法一:
    AppActivate sTitle
    SendKeys "5"
方法二:
    AppActivate sTitle
    SendKeys vbKey5
方法三:
    SendMessage Hwnd, WM_KEYDOWN, vbKey5, 0&
    SendMessage Hwnd, WM_KEYUP, vbKey5, 0&
方法四:
    AppActivate sTitle
    keybd_event 53, 0, 0, 0
    keybd_event 53, 0, KEYEVENTF_KEYUP, 0
方法五:
    PostMessage lHwnd, WM_KEYDOWN, vbKey5, 0&
    PostMessage lHwnd, WM_KEYUP, vbKey5, 0&
--------------------------------------------------------------------------------------------------------------------------------------------------------
添加快速鍵
--------------------------------------------------------------------------------------------------------------------------------------------------------
需要VB API函數:
GetAsyncKeyState                             ←判斷函式呼叫時指定虛擬鍵的狀態
--------------------------------------------------------------------------------------------------------------------------------------------------------
相關API聲明:
GetAsyncKeyState

Private Declare Function GetAsyncKeyState Lib "user32" (ByVal vkey As Long) As Integer
Private Function MyHotKey(vKeyCode) As Boolean
--------------------------------------------------------------------------------------------------------------------------------------------------------
需要的控制項:Timer(interval不為空)
--------------------------------------------------------------------------------------------------------------------------------------------------------
代碼:
Private Declare Function GetAsyncKeyState Lib "user32" (ByVal vkey As Long) As Integer
Private Function MyHotKey(vKeyCode) As Boolean
MyHotKey = (GetAsyncKeyState(vKeyCode) < 0)
End Function
'然後在迴圈中或Timer的Timer事件中檢測:
Private Sub Timer1_Timer()
If MyHotKey(vbKeyA) And vbKeyControl Then   'ctrl+A
End  '關閉
End If
'其中vbkeyA是鍵盤&#8243;A&#8243;的常數,其他鍵可按F1查得。
End Sub
--------------------------------------------------------------------------------------------------------------------------------------------------------
其它方法:
比如按下"ctrl+A"就退出!
'可以設置Form的KeyPreview屬性為True,然後在Form_KeyDown事件中添加代碼:
Private Sub Form_KeyDown(KeyCode As Integer, Shift As Integer)      
If KeyCode = Asc("A") And Shift = vbCtrlMask Then  unload me '如果ctrl+A鍵被按下就退出
End Sub
您需要登錄後才可以回帖 登錄 | 註冊

本版積分規則

小黑屋|Archiver|手機版|InPowerS.Net

GMT+8, 2024-3-29 04:04

Powered by Discuz! X3.4

© 2001-2017 Comsenz Inc.

快速回復 返回頂部 返回列表