Windows Vista Forums
Vista Forums Home Join Vista Forums Windows 7 Forum Vista Tutorials Tags
Welcome to Windows Vista Forums. Our forum is dedicated to helping you find solutions with any problems, errors or issues you are experiencing with Windows Vista. The Vista forum also covers news and updates and has an extensive Windows Vista tutorial section that covers a wide range of tips and tricks.

Go Back   Vista Forums > Misc Newsgroups > VB Script

Vista - move mouse

Reply
 
Old 07-22-2008   #1 (permalink)
Mike Brearley


 
 

move mouse

Is there a way in VBScript to move the mouse to a specific screen location
and perform a mouse button action? ANy help on this would be greatly
appreciated.

Thanks...

--
Mike



My System SpecsSystem Spec
Old 07-22-2008   #2 (permalink)
krazymike


 
 

Re: move mouse

To move your mouse:

Private Declare Function SetCursorPos Lib "user32" (ByVal x As Long,
ByVal y As Long) As Long

Private Sub someSub()
dim someX as Long, someY as Long
someX = 400
someY = 400
SetCursorPos someX, someY
End Sub

To perform events, go here: http://vb.mvps.org/samples/code/MouseEvent.zip

My System SpecsSystem Spec
Old 07-22-2008   #3 (permalink)
mr_unreliable


 
 

Re: move mouse

Mike Brearley wrote:
Quote:

> Is there a way in VBScript to move the mouse to a specific screen location
> and perform a mouse button action?
>
hi Mike,

I see "krazymike" suggesting that you call the "SetCursorPos"
api to move the mouse. This is assuming that you can declare
and call api's from script -- and declaring-and-calling api's
from script is something that is _NOT_ built into the wsh/vbs
language (at least the wsh/vbs language that I'm familiar with).
Sorry.

You can call api's from script, but only if you are willing to
use a third-party object to do it. One such third-party object
is DynaWrap (see "boilerplate" below.

If you wish to do A LOT of calling api's, then I would suggest
that you use some other scripting language that allows for calling
api's directly. Here are a couple:

FBSL: http://www.fbsl.net/phpbb2/index.php
o'Basic http://obasic.com/

I used to also recommend autoit3, but since they dropped support
of win98 (my os of choice), I have stopped recommending them.

cheers, jw
____________________________________________________________

You got questions? WE GOT ANSWERS!!! ..(but, no guarantee
the answers will be applicable to the questions)

--- <DynaWrap Boilerplate> ---
It is possible to declare-and-call an api from script,
but you must use a third-party control to do so,
or else write one yourself.

It has already been correctly pointed out that there
is no api-capability in "pure" script.

If you are willing to use a third-party control, then
one such control, called "DynaWrap", can be found on
Guenter Born's website (note: Guenter refers to it as
"DynaCall"). Here is the link to it:

http://people.freenet.de/gborn/WSHBa...SHDynaCall.htm

- or -

http://ourworld.compuserve.com/homep...SHDynaCall.htm

On that page you will find a download for the control,
plus some code samples.

Note: you may find additional sample code by searching
the archives of the wsh and vbscript ng's.

Note also: DynaWrap does have its limitations. There are
certain things it can't do. For example, you can't call
api's "by ordinal". (I had previously asserted that you
can't use DynaWrap to call api's which take typedefs as
parameters, but I have been proven wrong on that --
although it took me about two weeks to figure out how it
was done). Regardless, Dynawrap will work for most of
"the usual suspects".

And finally, DynaWrap doesn't work entirely as advertised.
For example, it is supposed to allow for the declaration of
several api definitions in one instance of itself. I could
never get that to work (in win9x -- but others have shown
this to work as advertised under winNT). With win98, you
will need a new instance of DynaWrap for every api, or else
re-instantiate the object for every api. Someday I'm going
to learn enough c++ to fix that...

Another possibility (for calling api's from script is XNeat:

http://www.xneat.com/doc/call_win32_api.html

One other thing. While the above discussion is oriented to
calling the system api's, contained in the user32, kernel32,
gdi32 and other system dll's, you could use DynaWrap (and
other similiar utilities) to call the exported interfaces
to ANY dll.

--- </DynaWrap Boilerplate> ---
My System SpecsSystem Spec
Old 07-22-2008   #4 (permalink)
Tom Lavedas


 
 

Re: move mouse

On Jul 22, 8:31 am, "Mike Brearley"
<mike_NOSPAM_brear...@xxxxxx> wrote:
Quote:

> Is there a way in VBScript to move the mouse to a specific screen location
> and perform a mouse button action? ANy help on this would be greatly
> appreciated.
>
> Thanks...
>
> --
> Mike
What, exactly, are you trying to accomplish? Do you actually have to
use the mouse? Is there a keyboard option available in the
application you want this to apply to?

I ask, because, as you can see from the other responses, WSH/VBS
cannot do this, but it does have provisions (albeit fairly
rudimentary) to send keystrokes to selected applications through the
AppActivate and Sendkeys methods. Unfortunately, the WSH
documentation on this subject STINKS. Beyond the syntax, the examples
are absolutely the PITS. If after taking a quick look at the docs,
you think this approach might do the job, come back here and describe
what you're trying to accomplish and the setup of the application you
are trying to automate and I or someone else will give you some
pointers on how to actually make this approach work. The way the
documents suggest using these is a TOTAL waste of time, but with care
(and for personal use) it can be made to work most of the time.

My signature is applied to this message via a Sendkeys interface to
the google groups web interface.

Tom Lavedas
===========
http://members.cox.net/tglbatch/wsh/
My System SpecsSystem Spec
Old 07-23-2008   #5 (permalink)
Mike Brearley


 
 

Re: move mouse

Thank all of you for your reply. I may just use a macro recorder like
jitbit to accomplish what I need.

--
Mike


"Mike Brearley" <mike_NOSPAM_brearley@xxxxxx> wrote in message
news:uk44ob$6IHA.5820@xxxxxx
Quote:

> Is there a way in VBScript to move the mouse to a specific screen location
> and perform a mouse button action? ANy help on this would be greatly
> appreciated.
>
> Thanks...
>
> --
> Mike
>

My System SpecsSystem Spec
Old 07-24-2008   #6 (permalink)
Sa6ry


 
 

calling win32 api from vb script

for calling win32 api from within VBScript check out this tool

www.vbs2exe.com

it convert your vbscript into Exe



"Mike Brearley" <mike_NOSPAM_brearley@xxxxxx> wrote in message
news:uk44ob$6IHA.5820@xxxxxx
Quote:

> Is there a way in VBScript to move the mouse to a specific screen location
> and perform a mouse button action? ANy help on this would be greatly
> appreciated.
>
> Thanks...
>
> --
> Mike
>


-- Posted on news://freenews.netfront.net - Complaints to news@xxxxxx --
My System SpecsSystem Spec
Old 07-24-2008   #7 (permalink)
Sa6ry


 
 

calling win32 API from vbscript

For calling win32 api from vbscript and much more

check www.vbs2exe.com

for example to set the mouse in position 10 & 10 you simply use the below command

XNHost.call "user32.dll", "SetCursorPos" , 10 , 10

Best Regards,
Sa6ry
www.xneat.com

My System SpecsSystem Spec
Old 07-28-2008   #8 (permalink)
unbobo


 
 

Re: move mouse

On Jul 22, 9:31*pm, "Mike Brearley"
<mike_NOSPAM_brear...@xxxxxx> wrote:
Quote:

> Is there a way in VBScript to move the mouse to a specific screen location
> and perform a mouse button action? *ANy help on this would be greatly
> appreciated.
>
> Thanks...
>
> --
> Mike
Do you have Excel?

------------------------------

Option Explicit

Dim excel
Dim messagepos
Dim x
Dim y

set excel = Wscript.CreateObject("Excel.Application")

messagepos =
excel.ExecuteExcel4Macro("CALL(""user32"",""GetMessagePos"",""J"")")

x = CLng("&H" & Right(Hex(messagepos), 4))
y = CLng("&H" & Left(Hex(messagepos), (Len(Hex(messagepos)) - 4)))

excel.ExecuteExcel4Macro("CALL(""user32"",""SetCursorPos"",""JJJ""," &
x & " + 300," & y & " + 300)")
My System SpecsSystem Spec
Old 08-05-2008   #9 (permalink)
Bishop


 
 

RE: move mouse

Yes, when you have Excel installed.

here is the Script:
http://www.scriptbox.at.tt/index.php...el%20Macro.vbs

Call it like this
"...Position and optional Mouse Click via Excel Macro.vbs" xPos,yPos,LeftClick

Example:
"...Position and optional Mouse Click via Excel Macro.vbs" 100,300,1

The value auf LeftClick is 0 or 1
1 = Click Event
0 = no Click Event


"Mike Brearley" wrote:
Quote:

> Is there a way in VBScript to move the mouse to a specific screen location
> and perform a mouse button action? ANy help on this would be greatly
> appreciated.
>
> Thanks...
>
> --
> Mike
>
>
>
My System SpecsSystem Spec
Old 08-05-2008   #10 (permalink)
mike


 
 

RE: move mouse

I think someone mentioned an option that I like to use called O'basic. It's
a simple windows scripting language that is free from Celtech Software. Here
is an example of how to move the mouse with O'basic(straight from the manual)
:

' This example brings Notepad to the foreground and
' closes it through the system menu, assuming
' Notepad is maximized
FindWindow "*Notepad"
SendMouse "LDC", 8, 8

Hope this helps,
Mike

url:http://www.ureader.com/msg/16758424.aspx
My System SpecsSystem Spec
Reply

Thread Tools


Similar Threads
Thread Forum
Mouse Pointer Animation does not move Vista General
Re: Mouse Pointer Animation does not move Vista performance & maintenance
Mouse Will not move when switching users Vista General
Does your mouse pointer move all on it's own? Vista hardware & devices
Mouse Will not Move After Upgrade to Vista Vista hardware & devices


Vista Forums is an independent web site and has not been authorized,
sponsored, or otherwise approved by Microsoft Corporation.
"Windows Vista", the Start Orb, and related materials are trademarks of Microsoft Corp.
© Designer Media Ltd

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46