新建一工程,放乙個按鈕command1,放乙個時鐘timer1,拷貝下列**執行,按按鈕一下會發現滑鼠隨機移動,碰到邊界會**,再按按鈕一下(或回車鍵)會停止。
'*****************************拷貝下列*******************************************
privatetype pointapi
x aslong
y as
long
endtype
private
declare
function getcursorpos lib
"user32
" (lppoint as pointapi) as
long
private
declare
function setcursorpos lib
"user32
" (byval x as
long, byval y as
long) as
long
dim rndx as
integer, rndy as
integer
'定義隨機移動方向和速率
private
subcommand1_click()
if rndx <> 0
and rndy <> 0
then
rndx = 0
rndy = 0
exit sub
endif
while rndx = 0
rndx = rnd * 20 - 10
wend
while rndy = 0
rndy = rnd * 20 - 10
wend
end sub
private
subform_load()
timer1.interval = 10
end sub
private
subtimer1_timer()
dim pos as pointapi, x as
long, y as
long
if rndx = 0
and rndy = 0
then
rndexit sub
endif
getcursorpos pos
x = pos.x +rndx
y = pos.y +rndy
if x < 20
then
x = 20
rndx = rndx * (-1)
endif
if x >= screen.width / 15 - 60
then
x = screen.width / 15 - 60
rndx = rndx * (-1)
endif
if y < 20
then
y = 20
rndy = rndy * (-1)
endif
if y >= screen.height / 15 - 100
then
y = screen.height / 15 - 100
rndy = rndy * (-1)
endif
setcursorpos x, y
end sub
**:
滑鼠事件 跟隨滑鼠移動
案例分析 1.滑鼠不斷移動,使用滑鼠移動事件 mousemove 2.在頁面中不斷移動,給document註冊事件 3.要移動距離,而且不佔位置,我們使用絕對定位 效果 跟隨滑鼠的天使 title 6 style 7img 11style 12head 13 body 14 img src pic....
滑鼠移動事件
當滑鼠指標位於元素上方時時,改變元素的背景色 p mouseover function 當滑鼠指標位於元素上方時,會發生 mouseover 事件。該事件大多數時候會與 mouseout 事件一起使用。mouseover 方法觸發 mouseover 事件,或規定當發生 mouseover 事件時執...
VB 全域性鍵盤 滑鼠鉤子
if code hc action then copymemory mousemsg,lparam,lenb mousemsg form1.txtmsg 1 text x str mousemsg.x y str mousemsg.y form1.txthwnd 1 format wparam,0 ...