移动鼠标 - VBScript和Excel宏 [英] Move Mouse - VBScript and Excel Macro

查看:245
本文介绍了移动鼠标 - VBScript和Excel宏的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

找到一个使用Excel在VBScript中移动鼠标的脚本。这几乎正​​是我正在寻找我的项目,但是我需要改变一点点,使我能够在代码中输入坐标来将鼠标专门移动到那些坐标;代码当前使用当前的鼠标位置并从该位置移动 - 我需要能够将鼠标移动到绝对位置,而不是相对位置。



这里是VBS代码:

  Option Explicit 
Dim Excel,GetMessagePos,x,y,Count,Position

设置Excel = WScript.CreateObject(Excel.Application)

GetMessagePos = Excel.ExecuteExcel4Macro(_
CALL(user32,GetMessagePos ,J))
x = CLng(& H& Right(Hex(GetMessagePos),4))
y = CLng(& H (GetMessagePos),(Len(Hex(GetMessagePos)) - 4)))

Position =+ 180
Position = - 180
Excel.ExecuteExcel4Macro
CALL(user32SetCursorPos,JJJ,&&&,&位置&))

WScript.Sleep(100)
WScript.Echo程序已结束

根据代码,鼠标的位置我s从它的CURRENT POSITION +180移动到-180。我需要这个代码改变,所以我可以把两个位置(变量名称X和Y),并使用它们来设置鼠标指针的确切位置。



我已经弄错了Excel.ExecuteExcel4Macro部分,并检查了该功能的文档无效。请你帮忙吗谢谢:)



编辑:我正在使用VBScript,因为我创建的系统是非常锁定的。我没有办法使用任何其他的技术吧,这样的帮助将不胜感激!

解决方案

首先,当你这样做

  Position =+ 180
Position = - 180

您首先设置位置为+180,然后立即覆盖它是-180。这没有意义



要更详细地回答您的问题,请更换此部分:

  x& &位置& ,& y& &位置

如下所示:

  x& ,& y 

在此之前,您必须说出光标的新坐标应该是什么,例如

  x =111
y =222
pre>

此外,所有这些都不需要,可以删除:

  GetMessagePos = Excel.ExecuteExcel4Macro(_ 
CALL(user32,GetMessagePos,J))
x = CLng(& H & Right(Hex(GetMessagePos),4))
y = CLng(& H& Left(Hex(GetMessagePos)),(Len(Hex(GetMessagePos))))

这是你获得旧光标位置的地方,你不需要这个,因为你说你不想要设定相对位置。



所有脚本都应该看起来像这样:

 选项显式
Dim Excel,x,y

设置Excel = WScript.CreateObject(Excel.Application)

x =111
y = 222
Excel.ExecuteExcel4Macro(_
CALL(user32,SetCursorPos,JJJ,& x&,& ;))

WScript.Sleep(100)
WScript.Echo程序已结束


Found a script that uses Excel to move the mouse in VBScript. This is almost exactly what I am looking for for my project, however I need to alter a small bit to enable me to enter coordinates in the code for it to move the mouse specifically to those coordinates; the code currently uses the current mouse position and moves from that position - I need to be able to have the mouse move to an ABSOLUTE position, not a RELATIVE one.

Here's the VBS code:

Option Explicit
Dim Excel, GetMessagePos, x, y, Count, Position

Set Excel = WScript.CreateObject("Excel.Application")

GetMessagePos = Excel.ExecuteExcel4Macro( _
    "CALL(""user32"",""GetMessagePos"",""J"")")
x = CLng("&H" & Right(Hex(GetMessagePos), 4))
y = CLng("&H" & Left(Hex(GetMessagePos), (Len(Hex(GetMessagePos)) - 4)))

Position = "+ 180"
Position = "- 180"
Excel.ExecuteExcel4Macro ( _
    "CALL(""user32"",""SetCursorPos"",""JJJ""," & x & " " & Position & "," & y & " " & Position & ")")

WScript.Sleep (100)
WScript.Echo "Program Ended"

According to the code, the position of the mouse is moved from it's CURRENT POSITION +180 then -180. I need this code altered so I can put both the positions (in variable names X and Y) and use those to set the exact position of the mouse pointer.

I have messed around with the Excel.ExecuteExcel4Macro part and checked out the documentation for the function to no avail. Please can you help? Thanks :)

EDIT: I'm using VBScript because the system I am creating this on is VERY locked down. I have no way of using any other technologies bar this one, so help would be appreciated!

解决方案

First of all, when you do this

Position = "+ 180"
Position = "- 180"

you're first setting Position to be "+180" and then immediately overwriting it to be "-180". There's no point in doing that.

To answer your question more specifically, replace this part:

x & " " & Position & "," & y & " " & Position

with something like this:

x & "," & y

Prior to that you'll have to say what the new coordinates of the cursor should be, e.g.

x = "111"
y = "222"

Also, all of this you don't need and can delete:

GetMessagePos = Excel.ExecuteExcel4Macro( _
    "CALL(""user32"",""GetMessagePos"",""J"")")
x = CLng("&H" & Right(Hex(GetMessagePos), 4))
y = CLng("&H" & Left(Hex(GetMessagePos), (Len(Hex(GetMessagePos)) - 4)))

That's where you get the old cursor position, and you don't need this since you say yourself you don't want to set a relative position.

All in all your script should look something like this:

Option Explicit
Dim Excel, x, y

Set Excel = WScript.CreateObject("Excel.Application")

x = "111"
y = "222"
Excel.ExecuteExcel4Macro ( _
    "CALL(""user32"",""SetCursorPos"",""JJJ""," & x & "," & y & ")")

WScript.Sleep (100)
WScript.Echo "Program Ended"

这篇关于移动鼠标 - VBScript和Excel宏的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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