gpt4 book ai didi

excel - 3D 游戏中控制中心鼠标

转载 作者:行者123 更新时间:2023-12-02 06:50:41 25 4
gpt4 key购买 nike

我有以下控制鼠标的代码(修改自 this source ):

Public Declare Function SetCursorPos Lib "user32" (ByVal x As Long, ByVal y As Long) As Long
Public 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)
Public Const MOUSEEVENTF_LEFTDOWN = &H2
Public Const MOUSEEVENTF_LEFTUP = &H4
Public Const MOUSEEVENTF_RIGHTDOWN As Long = &H8
Public Const MOUSEEVENTF_RIGHTUP As Long = &H10
Declare Sub Sleep Lib "kernel32" (ByVal dwMilliseconds As Long)
Sub Control()
Wait 3000
Pos 6, 145
Down
Pos 6, 149
Up
Pos 7, 147
Down
Up
Pos 8, 145
Down
Pos 8, 149
Up
Pos 10, 145
Down
Pos 10, 149
Up
Pos 11, 145
Down
Pos 12, 145
Up
Pos 11, 147
Down
Up
Pos 11, 149
Down
Pos 12, 149
Up
Pos 14, 145
Down
Pos 14, 149
Up
Pos 15, 149
Down
Pos 16, 149
Up
Pos 18, 145
Down
Pos 18, 149
Up
Pos 19, 145
Down
Pos 20, 145
Up
Pos 20, 146
Down
Pos 20, 146
Up
Pos 19, 147
Down
Pos 20, 147
Up
End Sub
Private Function Wait(Optional ByVal milliseconds As Long = 50)
Sleep milliseconds
End Function
Private Function Pos(ByVal x As Long, ByVal y As Long)
SetCursorPos x, y
End Function
Private Function Down()
mouse_event MOUSEEVENTF_LEFTDOWN, 0, 0, 0, 0
End Function
Private Function Up()
mouse_event MOUSEEVENTF_LEFTUP, 0, 0, 0, 0
End Function

它按预期工作并且可以在油漆上绘图。

现在我想要完成的是在 VRChat 游戏中进行 3D 绘图,将鼠标置于屏幕中间。

在游戏中,鼠标的向下和向上事件有效,但尝试更改其位置根本不会移动它。

该代码在游戏外有效,但在游戏中无法移动由鼠标控制的相机。我正在寻找的是能够使用代码自动移动游戏中的鼠标/摄像机。

VRChat 3D Drawing

最佳答案

下面是代码,您可以使用它循环移动光标

'Declare mouse events
Public Declare Function SetCursorPos Lib "user32" (ByVal x As Long, ByVal y As Long) As Long
Public 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)
Public Const MOUSEEVENTF_LEFTDOWN = &H2
Public Const MOUSEEVENTF_LEFTUP = &H4
Public Const MOUSEEVENTF_RIGHTDOWN As Long = &H8
Public Const MOUSEEVENTF_RIGHTUP As Long = &H10
'Declare sleep
Declare Sub Sleep Lib "kernel32" (ByVal dwMilliseconds As Long)

Sub CityscapeSkyline()
'Open MS Paint and select Natural pencil Brush with 6px width
For k = 1 To 3
SetCursorPos 16, 500
Sleep 50
mouse_event MOUSEEVENTF_LEFTDOWN, 0, 0, 0, 0
For i = 16 To 600 Step 5
For j = 500 To 300 Step -Int((180 - 10 + 1) * Rnd + 10)
SetCursorPos i, j
Sleep 10
Next j
Next i
mouse_event MOUSEEVENTF_LEFTUP, 0, 0, 0, 0
Next k
End Sub

如果您还需要使用当前光标位置,那么您也可以集成GetCursorPos

Declare Function GetCursorPos Lib "user32" (lpPoint As POINTAPI) As Long
' Create custom variable that holds two integers
Type POINTAPI
Xcoord As Long
Ycoord As Long
End Type

Sub GetCursorPosDemo()
Dim llCoord As POINTAPI
' Get the cursor positions
GetCursorPos llCoord
' Display the cursor position coordinates
MsgBox "X Position: " & llCoord.Xcoord & vbNewLine & "Y Position: " & llCoord.Ycoord
End Sub

PS:感谢https://wellsr.com/vba/2015/excel/vba-mouse-move-and-mouse-click-macro/

关于excel - 3D 游戏中控制中心鼠标,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49867822/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com