mouse_event不起作用(关于Windows API) [英] mouse_event didnt work (about windows API)

查看:138
本文介绍了mouse_event不起作用(关于Windows API)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如果我使用此方法来模拟鼠标单击.
它没有用.

mouse_event是Windows API的功能,用于模拟鼠标单击或鼠标可以执行的任何操作.

if i use this method to simulate mouse click.
it didnt work.

mouse_event is a function of windows API for simulate mouse click or whatever mouse can do.

Private Declare Function mouse_event Lib "user32.dll" Alias "mouse_event" _
(ByVal dwFlags As MouseEvent, ByVal dX As Int32, ByVal dY As Int32, _
 ByVal dwData As Int32, ByVal dwExtraInfo As Int32) As Boolean

Enum MouseEvent
    None
    Move = &H1
    AbsoluteLocation = &H8000
    LeftButtonDown = &H2
    LeftButtonUp = &H4
    MiddleButtonDown = &H20
    MiddleButtonUp = &H40
    RightButtonDown = &H8
    RightButtonUp = &H10
    Wheel = &H800
    WheelDelta = 120
    XButtonDown = &H100
    XButtonUp = &H200
End Enum





Sub Click()
       mouse_event(MouseEvent.LeftButtonDown, 0, 0, 0, 0)
       mouse_event(MouseEvent.LeftButtonUp, 0, 0, 0, 0)
End Sub



如果有SetCursorPos(100,100)
它可以工作,也许我知道为什么?? !!



if there have a SetCursorPos(100,100)
it will work may i know why ??!!

Sub Click()
       SetCursorPos(100,100)
       mouse_event(MouseEvent.LeftButtonDown, 0, 0, 0, 0)
       mouse_event(MouseEvent.LeftButtonUp, 0, 0, 0, 0)
End Sub

推荐答案

没有mouse_event这样的事件.这可能是您编写的某些方法或其他方法.我不知道这段代码中的MouseEvent是什么.您不能纠正谁知道什么然后问有关此问题的问题.这不是事件的工作方式.偶数只能在声明事件的类型的方法中触发;这是事件对常规委托实例的重要的傻瓜限制之一.您可以在事件中仅添加一个命名(非匿名)处理程序方法,并使该方法可访问(内部或公共),并且可以在您的类型实例的外部调用该方法.

您始终可以通过调用P/Invoked Windows API SendInput http://msdn.microsoft.com/en-us/library/ms646310(v = vs.85).aspx [
There is not such event as mouse_event. This is maybe some method you have written or something. I have not idea what it MouseEvent in this code. You cannot right who knows what and then ask question about it. This is not how events work. An even can only be fired in the method of the type where the event is declared; this is one of the important fool-proof limitations of event over regular delegate instances. You can add just one named (non-anonymous) handler method to the event and make this method accessible (internal or public), to it can be called outside of the instance of your type.

You can always simulate any input event by calling P/Invoked Windows API SendInput, http://msdn.microsoft.com/en-us/library/ms646310(v=vs.85).aspx[^].

Any kind of simulation of the input is not recommended to use in UI development, as UI libraries always provide clean and legitimate methods to achieve any useful effect. Simulation can only be used in limited number of special tasks, such as playing keyboard and/or mouse macro, on-screen keyboards and the like.

—SA


这篇关于mouse_event不起作用(关于Windows API)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆