当前位置:编程学习 > VB >>

如何实现鼠标后台移动

该用什么函数实现鼠标后台移动,就像按键精灵自带的插件一样,或361的BGKM6.dll插件 关注一下,看看是哪个函数 发送对应的消息。

http://www.google.com.hk/search?hl=zh-CN&source=hp&biw=788&bih=462&q=vb+%E5%8F%91%E9%80%81%E9%BC%A0%E6%A0%87%E6%B6%88%E6%81%AF+&oq=vb+%E5%8F%91%E9%80%81%E9%BC%A0%E6%A0%87%E6%B6%88%E6%81%AF+&aq=f&aqi=&aql=&gs_sm=e&gs_upl=734l7094l0l16l14l0l0l0l0l0l0l 参考AutoHotKey源代码http://www.autohotkey.com 利用Mouse_event吧,我也是利用这个事先鼠标的移动和各种单双击事件的
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
Const MOUSEEVENTF_MIDDLEDOWN = &H20
Const MOUSEEVENTF_MIDDLEUP = &H40
Const MOUSEEVENTF_MOVE = &H1
Const MOUSEEVENTF_ABSOLUTE = &H8000
Const MOUSEEVENTF_RIGHTDOWN = &H8
Const MOUSEEVENTF_RIGHTUP = &H10

之后随便你调用


如果用mouse_event那么鼠标是移动的。所以不是后台。 用 Mouse_event  setcursor 使用SetCursorPos可以设置鼠标的位置,mouse_event是触发鼠标事件的,不是设置鼠标位置的,同理也就不能移动鼠标。参阅:
Private Declare Function SetCursorPos Lib "user32" (ByVal x As Long, ByVal y As Long) As Long

'Example Name:Move Cursor
'This project needs 2 Buttons
Private Type POINTAPI
    x As Long
    y As Long
End Type
Private Declare Function ClientToScreen Lib "user32" (ByVal hwnd As Long, lpPoint As POINTAPI) As Long
Private Declare Function SetCursorPos Lib "user32" (ByVal x As Long, ByVal y As Long) As Long
Private Declare Function GetDeviceCaps Lib "gdi32" (ByVal hdc As Long, ByVal nIndex As Long) As Long

Dim P As POINTAPI
Private Sub Form_Load()
    'KPD-Team 1998
    'URL: http://www.allapi.net/
    'E-Mail: KPDTeam@Allapi.net

    Command1.Caption = "Screen Middle"
    Command2.Caption = "Form Middle"
    'API uses pixels
    Me.ScaleMode = vbPixels
End Sub
Private Sub Command1_Click()
    'Get information about the screen's width
    P.x = GetDeviceCaps(Form1.hdc, 8) / 2
    'Get information about the screen's height
    P.y = GetDeviceCaps(Form1.hdc, 10) / 2
    'Set the mouse cursor to the middle of the screen
    ret& = SetCursorPos(P.x, P.y)
End Sub
Private Sub Command2_Click()
    P.x = 0
    P.y = 0
    'Get information about the form's left and top
    ret& = ClientToScreen&(Form1.hwnd, P)
    P.x = P.x + Me.ScaleWidth / 2
    P.y = P.y + Me.ScaleHeight / 2
    'Set the cursor to the middle of the form
    ret& = SetCursorPos&(P.x, P.y)
End Sub

http://download.csdn.net/detail/veron_04/1441577
http://download.csdn.net/detail/veron_04/1441577
引用 4 楼 ysyyrps1 的回复:
利用Mouse_event吧,我也是利用这个事先鼠标的移动和各种单双击事件的
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
Const MOUSEEVENTF_MIDDLEDOWN = &H20
Const MOUSEEVENTF_MIDDLEUP = &H40
Const MOUSEEVENTF_MOVE = &H1
Const MOUSEEVENTF_ABSOLUTE = &H8000
Const MOUSEEVENTF_RIGHTDOWN = &H8
Const MOUSEEVENTF_RIGHTUP = &H10

之后随便你调用

谁帮给这些常量加些注释啊?并且如何调用?多谢多谢啦。 mouse_event或者SendMessage完美解决一切。 如何实现鼠标后台移动,这个我能做,需要不,QQ1085992075
补充:VB ,  API
CopyRight © 2012 站长网 编程知识问答 www.zzzyk.com All Rights Reserved
部份技术文章来自网络,