Thursday, January 11, 2018

Cursors.io Script. Write anything!

Ever got frustrated in http://cursors.io game and wanted to yell at another person?  Well now you can!

This script requires you to have Excel installed, otherwise it will not work.

Have fun with it! Either copy and paste the code into notepad and save as a .vbs file, or download the file here.

 Public Const MOUSEEVENTF_LEFTDOWN = &H2  
 Public Const MOUSEEVENTF_LEFTUP = &H4  
 Public Const MOUSEEVENTF_RIGHTDOWN = &H8  
 Public Const MOUSEEVENTF_RIGHTUP = &H10  
 On Error Resume Next  
    ' GetCursorPos requires a variable declared as a custom data type  
    ' that will hold two integers, one for x value and one for y value  
    Class POINTAPI  
      Public X_Pos  
      Public Y_Pos  
    End Class  
  Set Excel = WScript.CreateObject("Excel.Application")  
  Set Orig = New POINTAPI  
  Set Start = New POINTAPI  
  Dim scode1,owb1,omod1, iSize, iDelay, iRpt, text  
  Set owb1=Excel.workbooks.add  
  iSize = InputBox("What size do you want? (1-50: Recommended 7)")  
  If iSize = "" Then  
  iSize = 7  
  End If  
  iDelay = InputBox("What delay do you want? (Recommended 90)")  
  If iDelay = "" Then  
  iDelay = 90  
  End If  
  iRpt = InputBox("How many times would you like to repeat the text?")  
  If iRpt = "" Then  
  iRpt = 1  
  End If  
  scode1="Public Declare PtrSafe 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)" & vbCrLf  
  scode1= scode1 & "Declare PtrSafe Function GetCursorPos Lib ""user32"" (lpPoint As POINTAPI) As Long" & vbCrLf  
  scode1= scode1 & "Public Declare PtrSafe Sub keybd_event Lib ""user32"" (ByVal bVk As Byte, ByVal bScan As Byte, ByVal dwFlags As Long, ByVal dwExtraInfo As Long)" & vbCrLf  
  scode1= scode1 & "Public Declare PtrSafe Function MapVirtualKey Lib ""user32"" Alias ""MapVirtualKeyA"" (ByVal wCode As Long, ByVal wMapType As Long) As Byte" & vbCrLf  
  scode1= scode1 & "Type POINTAPI" & vbcrlf & "X_Pos As Long" & vbcrlf & "Y_Pos As Long" & vbcrlf & "End Type" & vbCrLf  
  scode1= scode1 & "Public Const KEYEVENTF_EXTENDEDKEY = &H1" & vbCrLf  
  scode1= scode1 & "Public Const KEYEVENTF_KEYUP = &H2" & vbCrLf  
  scode1 = scode1 & "Sub doMouse (Event1)" & vbcrlf  
  scode1 = scode1 & "mouse_event Event1, 0, 0, 0, 0" & vbCrLf  
  scode1 = scode1 & "End Sub" & vbCrLf  
  scode1 = scode1 & "Function getX ()" & vbcrlf  
  scode1 = scode1 & "Dim myPos as POINTAPI" & vbcrlf  
  scode1 = scode1 & "GetCursorPos myPos" & vbcrlf  
  scode1 = scode1 & "getX = myPos.X_Pos" & vbcrlf  
  scode1 = scode1 & "End Function" & vbcrlf  
  scode1 = scode1 & "Function getY ()" & vbcrlf  
  scode1 = scode1 & "Dim myPos as POINTAPI" & vbcrlf  
  scode1 = scode1 & "GetCursorPos myPos" & vbcrlf  
  scode1 = scode1 & "getY = myPos.Y_Pos" & vbcrlf  
  scode1 = scode1 & "End Function" & vbCrLf  
  scode1 = scode1 & "Sub myShiftKey (isDown as Boolean)" & vbcrlf  
  scode1 = scode1 & "If isDown then" & vbcrlf  
  scode1 = scode1 & "keybd_event &H10, MapVirtualKey(&H10, 0), 0, 0" & vbcrlf  
  scode1 = scode1 & "else" & vbCrLf  
  scode1 = scode1 & "keybd_event &H10, MapVirtualKey(&H10, 0), KEYEVENTF_KEYUP, 0" & vbCrLf  
  scode1 = scode1 & "End If" & vbCrLf  
  scode1 = scode1 & "End Sub" & vbCrLf  
  Set omod1=owb1.vbproject.vbcomponents.add(1)  
  omod1.codemodule.addfromstring scode1  
 For iL = 1 To iRpt  
  Move_Cursor  
  SetCursorPos1 start.X_Pos, Start.Y_Pos  
  start.x_pos = start.x_pos + 1  
 Next  
 'cleanup  
  Set omod1=nothing  
  owb1.saved=true  
  owb1.close  
  Set owb1=nothing  
  Excel.quit  
  Set Excel=Nothing  
  If Err.Number <> 0 Then  
  MsgBox "Error Occurred: " & Err.Description  
  End If  
 Sub Move_Cursor()  
   'Dim Hold As POINTAPI  
   Set Hold = New POINTAPI  
   'Dim text As String  
   'Dim i As Integer  
   'you must always start and end in the upper left corner  
   If start.X_Pos = 0 Then  
    text = InputBox("What Do you want to write with the mouse?")  
    WScript.Sleep 4000  
   End If  
   GetCursorPos1 orig  
   If start.X_Pos = 0 Then  
    GetCursorPos1 Start  
   End If  
   For i = 1 To Len(text)  
    shiftDown True  
    WScript.Sleep iDelay/2  
     mouse_event1 MOUSEEVENTF_LEFTDOWN   
     Select Case LCase(Mid(text, i, 1))  
       Case "a"  
         down  
         down  
         up  
         right  
         up  
         left  
         right  
         down  
         down  
         up  
         up  
         left  
       Case "b"  
         right  
         down  
         left  
         up  
         down  
         down  
         right  
         up  
         up  
         left  
       Case "c"  
         right  
         left  
         down  
         down  
         right  
         left  
         up  
         up  
       Case "d"  
         right  
         down  
         down  
         left  
         up  
         up  
       Case "e"  
         right  
         left  
         down  
         right  
         left  
         down  
         right  
         left  
         up  
         up  
       Case "f"  
         right  
         left  
         down  
         right  
         left  
         down  
         up  
         up  
       Case "g"  
         right  
         down  
         down  
         left  
         right  
         up  
         left  
         up  
       Case "h"  
         down  
         right  
         up  
         down  
         down  
         up  
         left  
         down  
         up  
         up  
       Case "i"  
         right  
         down  
         down  
         left  
         right  
         right  
         left  
         up  
         up  
         right  
         left  
       Case "j"  
         right  
         down  
         down  
         left  
         up  
         down  
         right  
         up  
         up  
         left  
       Case "k"  
         down  
         diagupRight  
         diagdownLeft  
         diagdownRight  
         diagupLeft  
         down  
         up  
         up  
       Case "l"  
         down  
         down  
         right  
         left  
         up  
         up  
       Case "m"  
         down  
         down  
         up  
         up  
         right  
         down  
         up  
         right  
         down  
         down  
         up  
         up  
         left  
       Case "n"  
         down  
         up  
         right  
         down  
         up  
         left  
       Case "o"  
         down  
         right  
         up  
         left  
       Case "p"  
         down  
         down  
         up  
         right  
         up  
         left  
       Case "q"  
         down  
         right  
         up  
         left  
         right  
         down  
         down  
         right  
         left  
         up  
         up  
       Case "r"  
         down  
         down  
         up  
         diagdownRight  
         diagupLeft  
         right  
         up  
         left  
       Case "s"  
         right  
         left  
         down  
         right  
         down  
         left  
         right  
         up  
         left  
         up  
       Case "t"  
         right  
         down  
         down  
         up  
         up  
         right  
         left  
       Case "u"  
         down  
         right  
         up  
         down  
         left  
         up  
       Case "v"  
         diagdownRight  
         diagupRight  
         diagdownLeft  
         diagupLeft  
       Case "w"  
         diagdownRight  
         diagupRight  
         diagdownRight  
         diagupRight  
         diagdownLeft  
         diagupLeft  
       Case "x"  
         diagdownRight  
         diagdownRight  
         diagupLeft  
         diagupRight  
         diagdownLeft  
         diagdownLeft  
         diagupRight  
         diagupLeft  
       Case "y"  
         diagdownRight  
         diagupRight  
         diagdownLeft  
         diagdownLeft  
         diagupRight  
         diagupLeft  
       Case "z"  
         right  
         diagdownLeft  
         right  
         left  
         diagupRight  
         left  
     End Select  
     mouse_event1 MOUSEEVENTF_LEFTUP  
     right  
     right  
   Next   
   shiftDown False  
 End Sub  
 Sub SetCursorPos1(x, y)  
  Excel.ExecuteExcel4Macro ("CALL(""user32"",""SetCursorPos"",""JJJ""," & x & "," & y & ")")  
 End Sub  
 Function GetCursorPos1(ByRef myPoint)  
  myPoint.X_Pos=Excel.run("getX")  
  myPoint.Y_Pos=Excel.run("getY")  
 End Function  
 Sub left()  
   'Dim Hold As POINTAPI  
   Set Hold = New POINTAPI  
   'GetCursorPos1 Hold  
   SetCursorPos1 orig.X_Pos - iSize, orig.Y_Pos  
   orig.X_pos = orig.x_pos - iSize  
   WScript.Sleep iDelay  
 End Sub  
 Sub right()  
   'Dim Hold As POINTAPI  
   Set Hold = New POINTAPI  
   'GetCursorPos1 Hold  
   SetCursorPos1 orig.X_Pos + iSize, orig.Y_Pos  
   orig.X_pos = orig.x_pos + iSize  
   WScript.Sleep iDelay  
 End Sub  
 Sub down()  
   'Dim Hold As POINTAPI  
   Set Hold = New POINTAPI  
   'GetCursorPos1 Hold  
   SetCursorPos1 orig.X_Pos, orig.Y_Pos + iSize  
   orig.y_pos = orig.y_pos + iSize  
   WScript.Sleep iDelay  
 End Sub  
 Sub up()  
   'Dim Hold As POINTAPI  
   Set Hold = New POINTAPI  
   'GetCursorPos1 Hold  
   SetCursorPos1 orig.X_Pos, orig.Y_Pos - iSize  
   orig.Y_pos = orig.y_pos - iSize  
   WScript.Sleep iDelay  
 End Sub  
 Sub diagdownRight()  
   'Dim Hold As POINTAPI  
   Set Hold = New POINTAPI  
   'GetCursorPos1 Hold  
   SetCursorPos1 orig.X_Pos + iSize, orig.Y_Pos + iSize  
   orig.X_pos = orig.x_pos + iSize  
   orig.y_pos = orig.y_pos + iSize  
   WScript.Sleep iDelay  
 End Sub  
 Sub diagupRight()  
   'Dim Hold As POINTAPI  
   Set Hold = New POINTAPI  
   'GetCursorPos1 Hold  
   SetCursorPos1 orig.X_Pos + iSize, orig.Y_Pos - iSize  
   orig.X_pos = orig.x_pos + iSize  
   orig.y_pos = orig.y_pos - iSize  
   WScript.Sleep iDelay  
 End Sub  
 Sub diagdownLeft()  
   'Dim Hold As POINTAPI  
   Set Hold = New POINTAPI  
   'GetCursorPos1 Hold  
   SetCursorPos1 orig.X_Pos - iSize, orig.Y_Pos + iSize  
   orig.X_pos = orig.x_pos - iSize  
   orig.y_pos = orig.y_pos + iSize  
   WScript.Sleep iDelay  
 End Sub  
 Sub diagupLeft()  
   'Dim Hold As POINTAPI  
   Set Hold = New POINTAPI  
   'GetCursorPos1 Hold  
   SetCursorPos1 orig.X_Pos - iSize, orig.Y_Pos - iSize  
   orig.X_pos = orig.x_pos - iSize  
   orig.y_pos = orig.y_pos - iSize  
   WScript.Sleep iDelay  
 End Sub  
 Sub mouse_event1 (myEvent)  
  Excel.run("DoMouse(" & myEvent & ")")  
 End Sub  
 Sub shiftDown (isDown)  
  Excel.run("myShiftKey(" & isDown & ")")  
 End Sub  

1 comment:

VBA Add an animated Notification Box to your Excel Program

For those of us who create programs and add-ins in Excel, we are very, very familiar with the message box.  The message box gives us the opp...