復雜的不會,來點兒簡單的,借用在listbox里按下鼠標時再移動,會高亮顯示選擇行,并且會隨鼠標移動而變化的這一特點改進的,不足之處是在listbox里,此時處于鼠標左鍵在按下狀態(tài)。
創(chuàng)新互聯(lián)公司主營夾江網(wǎng)站建設的網(wǎng)絡公司,主營網(wǎng)站建設方案,App定制開發(fā),夾江h(huán)5微信小程序開發(fā)搭建,夾江網(wǎng)站營銷推廣歡迎夾江等地區(qū)企業(yè)咨詢
Declare Sub mouse_event Lib "user32" (ByVal dwFlags As Long, ByVal dx As Long, ByVal dy As Long, ByVal cButtons As Long, ByVal dwExtraInfo As Long)
Public Const MOUSEEVENTF_LEFTDOWN = H2 '模擬鼠標左鍵按下
Private Sub ListBox1_MouseMove(sender As Object, e As MouseEventArgs) Handles ListBox1.MouseMove
mouse_event(MOUSEEVENTF_LEFTDOWN, 0, 0, 0, 0)
End Sub
錄制回放沒有問題,可是在鼠標移動過程中怎么去捕獲,鼠標進行了單擊,還是雙擊呢.捕獲不到回放的時候不知道什么時候該單擊還是雙擊.
直接把消息發(fā)送給TextBox。
Dim x As Integer, y As Integer
x = 100
y = 100
PostMessage(TextBox1.Handle.ToInt32, WM_LBUTTONDOWN, MK_LBUTTON, MakeInteger(x, y))
PostMessage(TextBox1.Handle.ToInt32, WM_LBUTTONUP, MK_LBUTTON, MakeInteger(x, y))
夢西已經(jīng)屏蔽了mouse_event,防止自動練級……
所以很遺憾,這個API在這里用不了。
調(diào)用api
在Visual Baisc.net中的聲明:
Declare Sub mouse_event Lib "user32" (ByVal dwFlags As Long, ByVal dx As Long, ByVal dy As Long, ByVal cButtons As Long, ByVal dwExtraInfo As Long)
Public Const MOUSEEVENTF_LEFTDOWN = H2 '模擬鼠標左鍵按下
Public Const MOUSEEVENTF_LEFTUP = H4 ’模擬鼠標左鍵釋放
Public Const MOUSEEVENTF_MIDDLEDOWN = H20 '模擬鼠標中間鍵按下
Public Const MOUSEEVENTF_MIDDLEUP = H40 '模擬鼠標中間鍵釋放
Public Const MOUSEEVENTF_RIGHTDOWN = H8 '模擬鼠標右鍵按下
Public Const MOUSEEVENTF_RIGHTUP = H10 '模擬鼠標右鍵釋放
Public Const MOUSEEVENTF_MOVE = H1 '模擬鼠標指針移動
例:
mouse_event MOUSEEVENTF_LEFTDOWN,10,10,0,0
'在(10,10)模擬鼠標左鍵按下
Declare Sub mouse_event Lib "user32" Alias "mouse_event" (ByVal dwFlags As Integer, ByVal dx As Integer, ByVal dy As Integer, ByVal cButtons As Integer, ByVal dwExtraInfo As Integer)
Dim postion1 As New Point
mouse_event(H1 Or H8000, postion1.X * 65535 / 1366, postion1.Y * 65535 / 768, 0, 0)
'按絕對位置移動鼠標
'在鼠標坐標系統(tǒng)中,屏幕在水平和垂直方向上均勻分割成65535×65535個單元,
'當前所用顯示屏分辨率為1366*768
'所以要進行如上轉換
mouse_event(H2, 0, 0, 0, 0) '鼠標左鍵按下
mouse_event(H4, 0, 0, 0, 0) '鼠標左鍵彈起
msdn上有 mouse_event 的詳解,大致使用如上