@@ -908,6 +908,87 @@ public void WindowsToast() {
908908 //Todo - quite a bit of work
909909 }
910910
911+ [ DllImport ( "user32.dll" , EntryPoint = "SetCursorPos" ) ]
912+ private static extern bool SetCursorPos ( int x , int y ) ;
913+ public void MoveMouse ( String parameter ) {
914+ parameter = parameter . Trim ( new char [ ] { '(' , ')' , ' ' } ) ;
915+ String [ ] parameterSplit = parameter . Split ( ',' ) ;
916+
917+ // Error Checking
918+ // If there is the correct amount of arguments
919+ if ( parameterSplit . Length != 2 ) {
920+ Error ( "The parameter is either formatted incorrectly or does not have 2 values" ) ;
921+ // If param 1 is a number
922+ } else if ( ( Int32 . TryParse ( parameterSplit [ 0 ] , out int param1 ) ) ) {
923+ if ( ( Int32 . TryParse ( parameterSplit [ 1 ] , out int param2 ) ) ) {
924+ SetCursorPos ( Int32 . Parse ( parameterSplit [ 0 ] ) , Int32 . Parse ( parameterSplit [ 1 ] ) ) ;
925+ successMessage = "Moved Mouse to (" + ( Int32 . Parse ( parameterSplit [ 0 ] ) . ToString ( ) + ", " + Int32 . Parse ( parameterSplit [ 1 ] ) ) . ToString ( ) + ")" ;
926+ } else {
927+ Error ( "Parameter 2 is not a number" ) ;
928+ }
929+
930+ // It isn't a number
931+ } else {
932+ Error ( "Parameter 1 is not a number" ) ;
933+ }
934+ }
935+
936+ [ DllImport ( "user32.dll" , EntryPoint = "mouse_event" ) ]
937+ public static extern void mouse_event ( int dwFlags , int dx , int dy , int cButtons , int dwExtraInfo ) ;
938+ public const int MOUSEEVENTF_LEFTDOWN = 0x02 ;
939+ public const int MOUSEEVENTF_LEFTUP = 0x04 ;
940+ public void MouseLeftClick ( string parameter ) {
941+ // Try to get amount of times to click
942+ if ( Int32 . TryParse ( parameter , out int repeatAmount ) ) {
943+ for ( int count = 0 ; count < repeatAmount ; count ++ ) {
944+ mouse_event ( MOUSEEVENTF_LEFTDOWN , Cursor . Position . X , Cursor . Position . Y , 0 , 0 ) ;
945+ mouse_event ( MOUSEEVENTF_LEFTUP , Cursor . Position . X , Cursor . Position . Y , 0 , 0 ) ;
946+ successMessage = "Simulated pressing the Left mouse button " + repeatAmount + " times" ;
947+ }
948+ } else {
949+ Error ( "Repeat amount is not a munber" ) ;
950+ }
951+ }
952+
953+ public const int MOUSEEVENTF_RIGHTDOWN = 0x08 ;
954+ public const int MOUSEEVENTF_RIGHTUP = 0x10 ;
955+ public void MouseRightClick ( string parameter ) {
956+ // Try to get amount of times to click
957+ if ( Int32 . TryParse ( parameter , out int repeatAmount ) ) {
958+ for ( int count = 0 ; count < repeatAmount ; count ++ ) {
959+ mouse_event ( MOUSEEVENTF_RIGHTDOWN , Cursor . Position . X , Cursor . Position . Y , 0 , 0 ) ;
960+ mouse_event ( MOUSEEVENTF_RIGHTUP , Cursor . Position . X , Cursor . Position . Y , 0 , 0 ) ;
961+ successMessage = "Simulated pressing the Right mouse button " + repeatAmount + " times" ;
962+ }
963+ } else {
964+ Error ( "Repeat amount is not a munber" ) ;
965+ }
966+ }
967+
968+ public const int MOUSEEVENTF_MIDDLEDOWN = 0x20 ;
969+ public const int MOUSEEVENTF_MIDDLEUP = 0x40 ;
970+ public void MouseMiddleClick ( string parameter ) {
971+ // Try to get amount of times to click
972+ if ( Int32 . TryParse ( parameter , out int repeatAmount ) ) {
973+ for ( int count = 0 ; count < repeatAmount ; count ++ ) {
974+ mouse_event ( MOUSEEVENTF_MIDDLEDOWN , Cursor . Position . X , Cursor . Position . Y , 0 , 0 ) ;
975+ mouse_event ( MOUSEEVENTF_MIDDLEUP , Cursor . Position . X , Cursor . Position . Y , 0 , 0 ) ;
976+ successMessage = "Simulated pressing the Middle mouse button " + repeatAmount + " times" ;
977+ }
978+ } else {
979+ Error ( "Repeat amount is not a munber" ) ;
980+ }
981+ }
982+
983+ public void Wait ( string parameter ) {
984+ if ( Int32 . TryParse ( parameter , out int time ) ) {
985+ Thread . Sleep ( time ) ;
986+ successMessage = "Waited " + time + " miliseconds" ;
987+ } else {
988+ Error ( "Time Parameter is not a number" ) ;
989+ }
990+ }
991+
911992 /* End of actions */
912993 }
913994}
0 commit comments