Jump to content


Photo

How to make my script more friendly


  • Please log in to reply
10 replies to this topic

#1 Simong93

Simong93
  • Members
  • 33 posts

Posted 02 October 2012 - 09:43 AM

Hi all Ive spent the best part of a month now just messing around with this scripting and i am having so much fun but now its time i try and make things more user friendly i currently have the script bellow.

What i want to try and do now is to make it so when its click on it loads up a box that asks how many times you would like this macro to run and say they type 200 it would change the top section of my macro that says loop,38 to loop,200 then they press ok and it starts.

The last thing im after is my macro will only work on one of my pcs because the screen size is different is there any sort of way i can make it so they can enter there screen size say 800,600 and the macro will change all the cords to match or maybe a drop down box where they chose there screen size and it loads up one of the ready made macros.

Many thanks for all your help in advance peoples and also does anyone see anyway i can make this macro a bit more neater i think its perfect but it never helps to have a second pair of eyes.

^Lbutton::

loop,38
{

loop,7
{

loop,1  ;moveing to notepad
{
Mousemove, 506,106
}

loop,3  ;left clicking
{
Send {Lbutton}
}

loop,1 ;right clicking
{
Send {Rbutton}
}

loop,2 ; moveing down to copy
{
Send {down}
}

loop,1 ; selecting copy
{
Send {enter}
}

loop,1  ;moveing down on notepad
{
Mousemove, 542,309
}

loop,1  ;left clicking
{
Send {Lbutton}
}

loop,1  ;moveing to excel
{
Mousemove, 643,125
}

loop,3  ;left clicking
{
Send {Lbutton}
}

loop,1 ;right clicking
{
Send {Rbutton}
}

loop,3 ; moveing down to copy
{
Send {down}
}

loop,1 ; selecting copy
{
Send {enter}
}

loop,1  ;moveing to right on excel
{
Mousemove, 690,329
}

loop,1  ;left click
{
Send {Lbutton}
}


loop,1  ;moveing to spare cell on excel
{
Mousemove, 468,227
}

loop,1  ;left click
{
Send {Lbutton}
}

loop,1  ;moveing back to notepad
{
Mousemove, -55,130
}

loop,1  ;left click
{
Send {Lbutton}
}
 ;END OF COPY AND PASTE
}

loop,1  ;moveing down on notepad
{
Mousemove, 542,309
}

loop,3  ;left clicking
{
Send {Lbutton}
}

loop,1  ;moveing to spare cell on excel
{
Mousemove, 919,272
}

loop,1  ;left click
{
Send {Lbutton}
}

loop,1  ;moveing down on excel
{
Mousemove, 706,314
}

loop,1  ;left clicking
{
Send {Lbutton}
}

loop,1  ;moveing left on excel
{
Mousemove, 439,329
}

loop,8  ;left clicking
{
Send {Lbutton}
}

loop,1  ;clicking on excel cell
{
Mousemove, 87,130
}

loop,1  ;left clicking
{
Send {Lbutton}
}

loop,1  ;going back to notepadd ++
{
Mousemove, -57,240
}

loop,1  ;left clicking
{
Send {Lbutton}
}

}
F1::Pause

return


#2 QuantumApocalypse

QuantumApocalypse
  • Members
  • 37 posts

Posted 02 October 2012 - 10:28 AM

For adding the user input loop, you're script could start like:
^LButton::
InputBox, out, Title,Please enter how many times you want to loop,, 410, 125 ;last two numbers are dimensions of dialogue
if ErrorLevel
    return
else
name:=out ;name and out are variable names. Just make sure they correspond to the above InputBox and are consistent throughout the script

Loop %name% {

etc,etc


#3 Simong93

Simong93
  • Members
  • 33 posts

Posted 02 October 2012 - 10:31 AM

For adding the user input loop, you're script could start like:

^LButton::
InputBox, out, Title,Please enter how many times you want to loop,, 410, 125 ;last two numbers are dimensions of dialogue
if ErrorLevel
    return
else
name:=out ;name and out are variable names. Just make sure they correspond to the above InputBox and are consistent throughout the script

Loop %name% {

etc,etc


Could you explain how this works thanks i think i have a rougth idea. im guesing Inputbox is what makes the box with the input section but how would it make just a normal box with say a button in it.

Out is the number that is enter in the box is that corrent.

I would never have thought it would be so easy like that thanks also with this in mind would i be able to load a box and open say a word doc inside of it with a set pair of dimensions and then the macro should turn universal correct me if im wrong of course.

#4 QuantumApocalypse

QuantumApocalypse
  • Members
  • 37 posts

Posted 02 October 2012 - 10:43 AM

As for the code, you don't need to add (Loop, 1) for something that executes once, all you need is to just leave the action by itself and it will run through it once :p
^Lbutton::
loop, 38 {
loop,7 {
Mousemove, 506,106
Send {click 3}
Send {Rbutton}
Send {down 2}
Send {enter}
Mousemove, 542,309
Send {Lbutton}
Mousemove, 643,125
Send {Lbutton 3}
Send {Rbutton}
Send {down 3}
Send {enter}
Mousemove, 690,329
Send {Lbutton}
Mousemove, 468,227
Send {Lbutton}
Mousemove, -55,130
Send {Lbutton}
}

Mousemove, 542,309
Send {click 3}
Mousemove, 919,272
Send {Lbutton}
Mousemove, 706,314
Send {Lbutton}
Mousemove, 439,329
Send {Lbutton 8}
Mousemove, 87,130
Send {Lbutton}
Mousemove, -57,240
Send {Lbutton}
}
Return

F1::Pause
That *should* hopefully be the same still as what you've written.

I would never have thought it would be so easy like that thanks also with this in mind would i be able to load a box and open say a word doc inside of it with a set pair of dimensions and then the macro should turn universal correct me if im wrong of course.

What do you mean? You can use WinMove to resize and place windows on the screen in a similar fashion to your current computer, but your other computers would have to have screens larger than the area your script currently covers

InputBox gives a general overview of the function

#5 QuantumApocalypse

QuantumApocalypse
  • Members
  • 37 posts

Posted 02 October 2012 - 10:48 AM

Out is the name of the output variable, which is what the user enters. Title is the title of the box etc.

If Errorlevel checks for success or not, if not, script stops. Otherwise, under any normal circumstances it will pass this.

Name:= out defines the variable "name" from the literal string "out", and then Loop, %name% takes the name variable and uses it as the number of loops.

#6 Simong93

Simong93
  • Members
  • 33 posts

Posted 02 October 2012 - 10:52 AM

I mean for example that script i have written relies on a screen that i think 1080,800 but lets say my pc is 600,800 that script it now useless would there be away of letting the user pic there size then changing all the cords to correspond to that screen size if you get my drift.

#7 QuantumApocalypse

QuantumApocalypse
  • Members
  • 37 posts

Posted 02 October 2012 - 11:08 AM

I mean for example that script i have written relies on a screen that i think 1080,800 but lets say my pc is 600,800 that script it now useless would there be away of letting the user pic there size then changing all the cords to correspond to that screen size if you get my drift.

Ah yeah, I understand, but I'm not too sure on how to get that to work easily. You'll probably have to wait for the other users so come online and answer that for you :/

#8 Simong93

Simong93
  • Members
  • 33 posts

Posted 02 October 2012 - 11:17 AM

I mean for example that script i have written relies on a screen that i think 1080,800 but lets say my pc is 600,800 that script it now useless would there be away of letting the user pic there size then changing all the cords to correspond to that screen size if you get my drift.

Ah yeah, I understand, but I'm not too sure on how to get that to work easily. You'll probably have to wait for the other users so come online and answer that for you :/


Ok thats no problum you have been more then helpful many thanks for the help

#9 Blackholyman

Blackholyman
  • Members
  • 1204 posts

Posted 02 October 2012 - 10:05 PM

Trie to use the Keyboard and not the mouse to do you macro like :)
[color=#0000FF]send ^c[/color] [color=#008040]; Ctrl+c = Copy[/color]
[color=#008040]        ;~ Send {Rbutton} ;right clicking
        ;~ Send {down 3} ; moveing down to copy
        ;~ Send {enter} ; selecting copy[/color]
And the win commands like WinWait
[color=#008040]        ;~      Mousemove, 690,329  ;moveing to right on excel[/color]
[color=#0000FF]WinWait, Microsoft Excel
IfWinNotActive, Microsoft Excel
WinActivate, Microsoft Excel
WinWaitActive, Microsoft Excel[/color]
This is a god way to not relie on screen Coords

Hope it helps


#10 Simong93

Simong93
  • Members
  • 33 posts

Posted 03 October 2012 - 08:15 AM

Trie to use the Keyboard and not the mouse to do you macro like :)

[color=#0000FF]send ^c[/color] [color=#008040]; Ctrl+c = Copy[/color]
[color=#008040]        ;~ Send {Rbutton} ;right clicking
        ;~ Send {down 3} ; moveing down to copy
        ;~ Send {enter} ; selecting copy[/color]
And the win commands like WinWait
[color=#008040]        ;~      Mousemove, 690,329  ;moveing to right on excel[/color]
[color=#0000FF]WinWait, Microsoft Excel
IfWinNotActive, Microsoft Excel
WinActivate, Microsoft Excel
WinWaitActive, Microsoft Excel[/color]
This is a god way to not relie on screen Coords

Hope it helps


This sounds like a good thing to learn now but how would i get it to click on cell A1 for example

#11 Blackholyman

Blackholyman
  • Members
  • 1204 posts

Posted 03 October 2012 - 12:25 PM

WinActivate, ahk_class XLMAIN [color=#008040]; Activate Excel window by Class[/color]

Send ^{HOME} [color=#008040]; Ctrl+home Goto top left cell, aka [A1][/color]

return
Hope it helps