Re: [.NET] 請益讓滑鼠自動移動至設定處

作者: chinoyan   2018-06-20 06:18:06
※ 引述《morningjis (morning)》之銘言:
: 請輸入專案類型(網站專案或者應用程式專案):
: 小型專案測試
: 請教一下,我想要寫個小程式,
: 可以在螢幕的畫面上不同位置,自動執行滑鼠的按鍵動作,
: 目前有找到相關的程式碼,
: 但是是限於執行專案的介面上,
: 不過我是想可以執行程式後,
: 在螢幕桌面上的任何位置都可執行滑鼠的按鍵動作,
: 不曉得該如何改程式碼的部分呢?!
: 目前找到的程式碼部分如下:
: ' mouse_event moves in a coordinate system where
: ' (0, 0) is in the upper left corner and
: ' (65535,65535) is in the lower right corner.
: ' Convert the coordinates.
: Dim screen_bounds As Rectangle = Screen.GetBounds(pt)
: Dim x As Integer = CInt(pt.X * 65535 / screen_bounds.Width)
: Dim y As Integer = CInt(pt.Y * 65535 / screen_bounds.Height)
: 謝謝各位達人們!!!
GetForegroundWindow
SetForegroundWindow
ShowWindow
Sleep
SetCursorPos
以上API先了解一下
Private Const MOUSEEVENTF_LEFTDOWN As Long = &H2
Private Const MOUSEEVENTF_LEFTUP As Long = &H4
Public Sub LeftClick(X As Long, Y As Long)
SetCursorPos X, Y
mouse_event MOUSEEVENTF_LEFTDOWN, 0, 0, 0, 0 '左鍵按下
Sleep 100
mouse_event MOUSEEVENTF_LEFTUP, 0, 0, 0, 0 '左鍵放開
End Sub

Links booklink

Contact Us: admin [ a t ] ucptt.com