2014年4月15日 星期二

<開源> 滑鼠位置偵測



程式名稱:滑鼠位置偵測本站作者:米粒  本站網址:http://bps1331.blogspot.tw/

本站作者:米粒  本站網址:http://bps1331.blogspot.tw/

程式說明:
 1.開放原始碼讓大家研究
 2.請勿用於商業用途



教學開始:本站作者:米粒  本站網址:http://bps1331.blogspot.tw/

事前準備
 Text  *1
 Timer1 *1

程式碼Form1



'用ReleaseCapture配合GetAsyncKeyState比較容易
'表單請置一個Timer,2個TextBox

Private Type POINTAPI
    X As Long
    Y As Long
End Type

Const VK_LBUTTON = &H1

Private Declare Function SetCapture Lib "user32" (ByVal hwnd As Long) As Long
Private Declare Function ReleaseCapture Lib "user32" () As Long
Private Declare Function GetCursorPos Lib "user32" (lpPoint As POINTAPI) As Long
Private Declare Function GetAsyncKeyState Lib "user32" (ByVal vKey As Long) As Integer
Dim P As POINTAPI

Private Sub Form_Load()
    SetCapture Me.hwnd '擷取滑鼠
    Timer1.Interval = 50
    Timer1 = True
End Sub

Private Sub Form_Unload(Cancel As Integer)
    ReleaseCapture '釋放滑鼠
End Sub

Private Sub Timer1_Timer()
    If GetAsyncKeyState(VK_LBUTTON) Then '若按滑鼠左鍵時
       GetCursorPos P '擷取滑鼠位置
       Text1 = "X = " & P.X
       Text2 = "Y = " & P.Y
    End If
End Sub




專案檔懶人包下載:本站作者:米粒  本站網址:http://bps1331.blogspot.tw/
 點我下載


壓縮密碼:
 分享於- http://bps1331.blogspot.tw/


本站作者:米粒  本站網址:http://bps1331.blogspot.tw/
本站作者:米粒  本站網址:http://bps1331.blogspot.tw/

來源:截取自網路未知網頁

1 則留言:

  1. 不好意思 我想請問一下 關於滑鼠蛋的部分

    Text  *1
    Timer1 *1

    這兩個找不到= =

    回覆刪除

找東西嗎?來這搜尋看看吧!

閱讀前,請先點擊廣告,支持作者

點擊廣告,支持作者