怎么用vb显示鼠标在窗体外的坐标? 怎么用vb控制鼠标自动去到指定区域?(高手给答案加分!)
2个回答
展开全部
Private Type POINTAPI
x As Long
y As Long
End Type
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 position As POINTAPI
Private Sub Form_Load()
Timer1.Interval = 1
End Sub
Private Sub Timer1_Timer()
GetCursorPos position
Text3 = Text1
Text4 = Text2
Text1 = p.x
Text2 = p.y
End Sub
上面的代码GetCursorPos 是用来获取坐标,setcursorpos 是设置坐标的
x As Long
y As Long
End Type
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 position As POINTAPI
Private Sub Form_Load()
Timer1.Interval = 1
End Sub
Private Sub Timer1_Timer()
GetCursorPos position
Text3 = Text1
Text4 = Text2
Text1 = p.x
Text2 = p.y
End Sub
上面的代码GetCursorPos 是用来获取坐标,setcursorpos 是设置坐标的
追问
恩,谢谢你。但是我有几个问题问一下:
1,我还要在一个点(或者一个区域)自动点击啊~(譬如在(300,260))
2,SetCursorPos的作用怎么没有体现呢?
3,弱弱问一句Text1 = p.x 这个有是什么意思呢,将p.x赋值给text1?(为什么x前要加个p.????应该是position吧,但是加在上面是什么意思呢?)
希望指教
希望指教
追答
1、鼠标点击
Private 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)
Const MOUSEEVENTF_LEFTDOWN = &H2
Const MOUSEEVENTF_LEFTUP = &H4
以上放到声明中
mouse_event MOUSEEVENTF_LEFTDOWN Or MOUSEEVENTF_LEFTUP, 0, 0, 0, 0
以上放到过程中
2、SetCursorPos 后边跟着是两个数字..也就是度坐标,就没法加,自己按需要加吧
3、你的理解是对的,text1里边会随着鼠标的移动而变化。..... 就是position,我闹错啦
这个里定义了一个类型
Private Type POINTAPI
x As Long
y As Long
End Type
以上说明这个类型的变量有两个属性,我们把position设置成了个这类型,所以p.x表示的是横坐标,p.y是纵坐标,可以和Form.weight和Form.height相对应理解
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询