Developer's Closet A place where I can put my PHP, SQL, Perl, JavaScript, and VBScript code.

18Feb/101
Move Your Mouse Using VBScript and Excel

This script uses the GetMessagePos and SetCursorPos Windows API functions to move your mouse. The script will first get the current position of the mouse by calling GetMessagePos. Next, the script will move the mouse using SetCursorPos. All this is done through an Excel macro. You can call Excel macros through the ExecuteExcel4Macro method. Needless to say, Excel must be installed locally for this script to work. I've found this script very useful for fooling screensavers.

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

Do While Count < 10
	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)))
	If Count MOD 2 = 0 Then
		Position = "- 30"
	Else
		Position = "+ 30"
	End If
	Excel.ExecuteExcel4Macro("CALL(""user32"",""SetCursorPos"",""JJJ""," & x & " " & Position & "," & y & " " & Position & ")")

	WScript.Sleep(100)
	Count = Count + 1

Loop
WScript.Echo "Program Ended"

Reference: http://msdn.microsoft.com/en-us/library/aa191494%28office.10%29.aspx

Comments (1) Trackbacks (0)
  1. This script could also be used for left mouse clicks like this example:

    Excel.ExecuteExcel4Macro(“CALL(“”user32″”,””SetCursorPos””,””JJJ””,”x100″,”y 300″,” & LeftClick & “)”)

    The value of LeftClick is 0 or 1
    1 = Click Event
    0 = No Click Event


Leave a comment

No trackbacks yet.