使鼠标单击左键的VB命令是什么?

我说的不是触发控件的click事件后执行指定命令,而是触发了某一事件后使鼠标在指定坐标单击左键。

麻烦再说一下使单击右键,双击左键和滑动滚轮的命令

 1、首先我们要用FindWindow,知道游戏窗口的句柄,因为我们要通过它来得知游戏的运行后所在进程的ID,下面就是FindWindow的用法:

HWND FindWindow(

LPCTSTR lpClassName, // pointer to class name
LPCTSTR lpWindowName // pointer to window name
);

  2、我们GetWindowThreadProcessId来得到游戏窗口相对应进程的进程ID,函数用法如下:

DWORD GetWindowThreadProcessId(

HWND hWnd, // handle of window
LPDWORD lpdwProcessId // address of variable for process identifier
);

  3、得到游戏进程ID后,接下来的事是要以最高权限打开进程,所用到的函数OpenProcess的具体使用方法如下:

HANDLE OpenProcess(

DWORD dwDesiredAccess, // access flag
BOOL bInheritHandle, // handle inheritance flag
DWORD dwProcessId // process identifier
);

  在dwDesiredAccess之处就是设存取方式的地方,它可设的权限很多,我们在这里使用只要使用PROCESS_ALL_ACCESS 来打开进程就可以,其他的方式我们可以查一下MSDN。

  4、打开进程后,我们就可以用函数对存内进行操作,在这里我们只要用到WriteProcessMemory来对内存地址写入数据即可(其他的操作方式比如说:ReadProcessMemory等,我在这里就不一一介绍了),我们看一下WriteProcessMemory的用法:

BOOL WriteProcessMemory(

HANDLE hProcess, // handle to process whose memory is written to
LPVOID lpBaseAddress, // address to start writing to
LPVOID lpBuffer, // pointer to buffer to write data to
DWORD nSize, // number of bytes to write
LPDWORD lpNumberOfBytesWritten // actual number of bytes written
);

  5、下面用CloseHandle关闭进程句柄就完成了。

  这就是这类游戏外挂的程序实现部份的方法,好了,有了此方法,我们就有了理性的认识,我们看看实际例子,提升一下我们的感性认识吧,下面就是XX游戏的外挂代码,我们照上面的方法对应去研究一下吧:

const
ResourceOffset: dword = $004219F4;
resource: dword = 3113226621;
ResourceOffset1: dword = $004219F8;
resource1: dword = 1940000000;
ResourceOffset2: dword = $0043FA50;
resource2: dword = 1280185;
ResourceOffset3: dword = $0043FA54;
resource3: dword = 3163064576;
ResourceOffset4: dword = $0043FA58;
resource4: dword = 2298478592;
var
hw: HWND;
pid: dword;
h: THandle;
tt: Cardinal;
begin
hw := FindWindow('XX', nil);
if hw = 0 then
Exit;
GetWindowThreadProcessId(hw, @pid);
h := OpenProcess(PROCESS_ALL_ACCESS, false, pid);
if h = 0 then
Exit;
if flatcheckbox1.Checked=true then
begin
WriteProcessMemory(h, Pointer(ResourceOffset), @Resource, sizeof(Resource), tt);
WriteProcessMemory(h, Pointer(ResourceOffset1), @Resource1, sizeof(Resource1), tt);
end;
if flatcheckbox2.Checked=true then
begin
WriteProcessMemory(h, Pointer(ResourceOffset2), @Resource2, sizeof(Resource2), tt);
WriteProcessMemory(h, Pointer(ResourceOffset3), @Resource3, sizeof(Resource3), tt);
WriteProcessMemory(h, Pointer(ResourceOffset4), @Resource4, sizeof(Resource4), tt);
end;
MessageBeep(0);
CloseHandle(h);
close;
温馨提示:内容为网友见解,仅供参考
第1个回答  2013-08-24
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)
Private Const MOUSEEVENTF_LEFTDOWN = &H2
Private Const MOUSEEVENTF_LEFTUP = &H4
Private Const MOUSEEVENTF_MIDDLEDOWN = &H20
Private Const MOUSEEVENTF_MIDDLEUP = &H40
Private Const MOUSEEVENTF_MOVE = &H1 '移动鼠标
Private Const MOUSEEVENTF_ABSOLUTE = &H8000
Private Const MOUSEEVENTF_RIGHTDOWN = &H8
Private Const MOUSEEVENTF_RIGHTUP = &H10
Private Declare Sub Sleep Lib "kernel32" (ByVal dwMilliseconds As Long)
Private Declare Function SetCursorPos Lib "user32" (ByVal X As Long, ByVal Y As Long) As Long

Private Sub Command1_Click()
SetCursorPos x坐标, y坐标
Sleep 200
mouse_event MOUSEEVENTF_LEFTDOWN, 0, 0, 0, 0 '按下鼠标左键
mouse_event MOUSEEVENTF_LEFTUP, 0, 0, 0, 0 '松开鼠标左键
Sleep 200
mouse_event MOUSEEVENTF_RIGHTDOWN, 0, 0, 0, 0 '按下鼠标左键
mouse_event MOUSEEVENTF_RIGHTUP, 0, 0, 0, 0 '松开鼠标左键
Sleep 200
mouse_event MOUSEEVENTF_MIDDLEDOWN, 0, 0, 0, 0 '滑轮向后
mouse_event MOUSEEVENTF_MIDDLEUP, 0, 0, 0, 0 '滑轮向前
Sleep 200
End Sub追问

这么复杂?
没有一个简单的单词或词组加坐标的方法么?

追答

前面带private的都是定义,看起来复杂,其实后面加注释的才是真正有用的方法。

本回答被网友采纳

使鼠标单击左键的VB命令是什么?
1、首先我们要用FindWindow,知道游戏窗口的句柄,因为我们要通过它来得知游戏的运行后所在进程的ID,下面就是FindWindow的用法:HWND FindWindow(LPCTSTR lpClassName, \/\/ pointer to class name LPCTSTR lpWindowName \/\/ pointer to window name );2、我们GetWind...

VB編寫鼠標自動移動點擊左鍵
还有一个设置鼠标移动到某个点上. Dim p As PointAPI SetCursorPos p 'p.x=? p.y=? 自己设置 记得采纳啊

VB识别鼠标左右键
MouseDown事件中 有个button变量 当鼠标右键按下时 button的值为vbRightButton,左键按下为vbRightButton,滚轮按下为4知道这个就好实现你所说的功能了你在Mousedown事件中添加下面代码:if button = vbRightButton thenmsgbox "按下右键"elseif button = vbLeftButton thenmsgbox "按下左键"判断左右键...

VB实现自动单击鼠标左键的代码是什么?
1. mouse_event 函数功能:该函数综合鼠标击键和鼠标动作。在Windows NT\/2000\/XP中,该函数已经被取消,使用SendInput函数代替。 函数原型: VOID mouse_event( DWORD dwFlags, \/\/ motion and click options DWORD dx, \/\/ horizontal position or change DWORD dy, \/\/ vertical position or change DW...

VB中如何把鼠标自动移到指定位置并单击?
单击Command1时鼠标会到(500,500)这个点作鼠标左键单击动作代码如下:Private Declare Function SetCursorPos Lib "user32" (ByVal x As Long, ByVal y As Long) As Long Private Declare Sub mouse_event Lib "user32" (ByVal dwFlags As Long, ByVal dx As Long, ByVal dy As Long, By...

如何用VB做鼠标连续点击左键
mouse_event MOUSEEVENTF_ABSOLUTE Or MOUSEEVENTF_MOVE, x, y, 0, 0 '鼠标移动 mouse_event MOUSEEVENTF_LEFTDOWN, 0, 0, 0, 0 '模拟鼠标的左键按下 mouse_event MOUSEEVENTF_LEFTUP, 0, 0, 0, 0 '模拟鼠标的左键抬起 End Sub 注:此法会移动鼠标,如果不想移动鼠标可用postmessage...

VB模拟5秒\/次单击鼠标左键
Private Const MOUSEEVENTF_LEFTDOWN = &H2 ' left button down Private Const MOUSEEVENTF_LEFTUP = &H4 ' left button up Private Sub form_load()timer1.interval=5000 end sub Private Sub Timer1_Timer()mouse_event MOUSEEVENTF_LEFTDOWN, 0, 0, 0, 0 '鼠标左键按下 mouse_event MOUSEEVENTF...

VB语言 “如果鼠标左键单击”的代码
为什么要用if呢 private sub command2_click()'你要出现的某某某是什么东西呢?'如果是出现一个提示 msgbox "你点击了按钮"'如果是要出现某个控件比如一个原来是不可见的文本框 text1.visalbe=true '如果是要出现一个新的窗体form2 form2.show '如果要关闭原来的窗体 me.hide end sub ...

vb编程 求鼠标左键自动单击的编程
Declare Sub mouse_event Lib "user32" Alias "mouse_event" (ByVal dwFlags As Long , ByVal dx As Long , ByVal dy As Long , ByVal cButtons As Long , ByVal dwExtraInfo As Long)然后在form1的load事件中添加:mouse_event (MOUSEEVENTF_LEFTDOWN ,2500,2500,0,0)mouse_event(...

vb 模拟鼠标点击
dy As Long, ByVal cButtons As Long, ByVal dwExtraInfo As Long) '定义鼠标事件 '上面的是声明部分.只有声明了,才可以使用..'代码部分 Call SetCursorPos(10, 20)'让鼠标移动到(10,20)mouse_event MOUSEEVENTF_LEFTDOWN Or MOUSEEVENTF_LEFTUP, 0, 0, 0, 0 '模拟鼠标的左键单击!

相似回答