当前位置 - 股票行情交易網 - 金融財經 - VB中keybd event和sendkeys的問題 。我想完成壹個功能, 可以使鼠標自動移動到VB之外的文本框中,單擊……

VB中keybd event和sendkeys的問題 。我想完成壹個功能, 可以使鼠標自動移動到VB之外的文本框中,單擊……

Private Declare Function GetFocus Lib "user32" () 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)

Private Declare Function AttachThreadInput Lib "user32" (ByVal idAttach As Long, ByVal idAttachTo As Long, ByVal fAttach As Long) As Long

Private Declare Function GetForegroundWindow Lib "user32" () As Long

Private Declare Function GetCurrentThreadId Lib "kernel32" () As Long

Private Declare Function GetWindowThreadProcessId Lib "user32" (ByVal hwnd As Long, lpdwProcessId As Long) As Long

Private WithEvents Timer1 As Timer

Private Sub Form_Load()

Set Timer1 = Me.Controls.Add("VB.Timer", "Timer")

Timer1.Interval = 1000

Timer1.Enabled = True

End Sub

Private Sub Timer1_Timer()

Dim CurrentID As Long

CurrentID = GetWindowThreadProcessId(GetForegroundWindow, ByVal 0&)

AttachThreadInput GetCurrentThreadId, CurrentID, True

PostMessage GetFocus, &H102, vbKey1, ByVal 0&

AttachThreadInput GetCurrentThreadId, CurrentID, False

End Sub