台灣最大程式設計社群網站
線上人數
1612
 
會員總數:239348
討論主題:185689
歡迎您免費加入會員
討論區列表 >> VB6 >> vb6模擬鍵盤迴圈打字
[ 變換順序 ]  
[我要回覆]
1
回應主題 加入我的關注話題 檢舉此篇討論 將提問者加入個人黑名單
vb6模擬鍵盤迴圈打字
價值 : 200 QP  點閱數:270 回應數:2

樓主

JJ
門外漢
0 5
76 7
發送站內信


程式說明
1、找到Enter the Password這個視窗並開啟
2、然後開始輸入文字1~999999999
3、每輸入一個字元,會按ENTER一下,然後在按清除10次

問題1、這種跑法會死當,能修正程式跑法,不會死當
2、怎麼帶入英文符號及特殊符號
3、當視窗不見後把輸入的字元在text2.text 顯示出來


Private Declare Function FindWindow Lib "user32" Alias "FindWindowA" (ByVal lpClassName As String, ByVal lpWindowName As String) As Long
Private Declare Function GetWindowThreadProcessId Lib "user32" (ByVal hwnd As Long, lpdwProcessId As Long) As Long
Private Declare Function OpenProcess Lib "kernel32" (ByVal dwDesiredAccess As Long, ByVal bInheritHandle As Long, ByVal dwProcessId As Long) As Long
Private Declare Function PostMessage Lib "user32" Alias "PostMessageA" (ByVal hwnd As Long, ByVal wMsg As Long, ByVal wParam As Long, lParam As Any) As Long
Private Declare Function SendMessage Lib "user32" Alias "SendMessageA" (ByVal hwnd As Long, ByVal wMsg As Long, ByVal wParam As Long, lParam As Any) As Long
Private Declare Function GetParent Lib "user32" (ByVal hwnd As Long) As Long
Private Declare Function WindowFromPoint Lib "user32" (ByVal xPoint As Long, ByVal yPoint As Long) As Long
Private Declare Function ShowWindow Lib "user32" (ByVal hwnd As Long, ByVal nCmdShow As Long) As Long
Private Declare Function GetClassName Lib "user32" Alias "GetClassNameA" (ByVal hwnd As Long, ByVal lpClassName As String, ByVal nMaxCount As Long) As Long

Private Declare Function GetWindowText Lib "user32" Alias "GetWindowTextA" (ByVal hwnd As Long, ByVal lpString As String, ByVal nMaxCount As Long) As Long
Const SW_SHOWNORMAL = 1
Private Declare Sub keybd_event Lib "user32" (ByVal bVk As Byte, ByVal bScan As Byte, ByVal dwFlags As Long, ByVal dwExtraInfo As Long)

Private Const KEYEVENTF_EXTENDEDKEY = &H1
Private Const KEYEVENTF_KEYUP = &H2

Private Const WM_CLOSE = &H10

Private Sub Command1_Click()

Dim hwnd As Long
Dim pid As Long
Dim xd As Long
Dim hproces1 As Long
Dim jj As String
Dim Password As Single




hwnd = FindWindow(vbNullString, "Enter the Password")
GetWindowThreadProcessId hwnd, pid
xd = OpenProcess(PROCESS_ALL_ACCESS, False, pid) '開啟process
hprocess = xd
If pid <> 0 Then
Label1.Caption = "已偵測到"
Else
Label1.Caption = "末偵測到"

If pid = 0 Then
MsgBox "無法取得ProcessID"
Exit Sub
End If
End If

Text1.Text = pid


'開啟視窗
ShowWindow WinWnd, SW_SHOWNORMAL
lpClassName = Space(256)
RetVal = GetClassName(WinWnd, lpClassName, 256)
AppActivate "Enter the Password"
keybd_event vbKeyTab, 0, KEYEVENTF_EXTENDEDKEY, 0
keybd_event vbKeyTab, 0, KEYEVENTF_KEYUP, 0
Password = 0

For i = 1 To 999999999



'Do Until pid <> 0
SendKeys Password
SendKeys "{ENTER}" '按enter鍵
Password = Password + 1
SendKeys "{BACKSPACE 10}" '如果還偵測到視窗清除鍵按10次





Text2.Text = Password



Next



End Sub






搜尋相關Tags的文章: [ 程式修改( ] , [ )虛擬鍵盤 ] ,
本篇文章發表於2017-01-12 16:51
別忘捐VP感謝幫助你的人 新手會員瞧一瞧
1樓
最有價值解答

MSDOS
捐贈 VP 給 MSDOS 檢舉此回應
迴圈要加 DoEvents 才不會當
跑個 1000 或 10000 次 加一次 DoEvents
自己試了

第二個問題查一下 SendKeys 用法
https://terry55wu.blogspot.tw/2009/06/vb6sendkeys.html
應該可以吧!
本篇文章回覆於2017-01-19 11:47
== 簽名檔 ==
--未登入的會員無法查看對方簽名檔--
2樓
作者回應

JJ
檢舉此回應
MSDOS 大大您好!
加入 DoEvents 不會當了,但跑的好慢,有別的跑法嗎?
本篇文章回覆於2017-01-23 16:38
== 簽名檔 ==
--未登入的會員無法查看對方簽名檔--
[ 變換順序 ]   
1

回覆
如要回應,請先登入.