vb隨機移動滑鼠

來源:互聯網
上載者:User

標籤:exit   click   thread   時鐘   declare   移動   style   隨機   form   

建立一工程,放一個按鈕command1,放一個時鐘timer1,拷貝下列代碼運行,按按鈕一下會發現滑鼠隨機移動,碰到邊界會反彈,再按按鈕一下(或斷行符號鍵)會停止。
‘*****************************拷貝下列代碼*****************************************

Private Type POINTAPI        x As Long        y As LongEnd TypePrivate Declare Function GetCursorPos Lib "user32" (lpPoint As POINTAPI) As LongPrivate Declare Function SetCursorPos Lib "user32" (ByVal x As Long, ByVal y As Long) As LongDim rndX As Integer, rndY As Integer  ‘定義隨機移動方向和速率Private Sub Command1_Click()  If rndX <> 0 And rndY <> 0 Then    rndX = 0    rndY = 0    Exit Sub  End If  While rndX = 0    rndX = Rnd * 20 - 10  Wend  While rndY = 0    rndY = Rnd * 20 - 10  WendEnd SubPrivate Sub Form_Load()  Timer1.Interval = 10End SubPrivate Sub Timer1_Timer()  Dim pos As POINTAPI, x As Long, y As Long  If rndX = 0 And rndY = 0 Then    Rnd    Exit Sub  End If  GetCursorPos pos  x = pos.x + rndX  y = pos.y + rndY  If x < 20 Then    x = 20    rndX = rndX * (-1)  End If  If x >= Screen.Width / 15 - 60 Then    x = Screen.Width / 15 - 60    rndX = rndX * (-1)  End If  If y < 20 Then    y = 20    rndY = rndY * (-1)  End If  If y >= Screen.Height / 15 - 100 Then    y = Screen.Height / 15 - 100    rndY = rndY * (-1)  End If  SetCursorPos x, yEnd Sub

 

轉自:http://bbs.bccn.net/thread-407793-1-1.html

vb隨機移動滑鼠

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.