Jump to content

Any way to make this faster ? Move mouse into direction until pixelgetcolor.


Recommended Posts

Hi,

I am currently using a pdf converter to turn checkboxes from a document, written in word, into a pdf which

can be filled out. Now I got like 100's of checkboxes and the programm only provides a manual drag and

drop field for them. So I quickly made this:

 

HotKeySet("c","Checkpixel")
HotKeySet("{ESC}", "Terminate")

While 1
    Sleep(10)
WEnd

Func Checkpixel()

   Do
   MouseMove(MouseGetPos(0)-1,MouseGetPos(1),0)
   Until PixelGetColor(MouseGetPos(0),MouseGetPos(1)) = 0x000000
   MouseMove(MouseGetPos(0)+1,MouseGetPos(1),0)

   Do
   MouseMove(MouseGetPos(0),MouseGetPos(1)-1,0)
   Until PixelGetColor(MouseGetPos(0),MouseGetPos(1)) = 0x000000
   MouseMove(MouseGetPos(0)-1,MouseGetPos(1),0)

   Local $aPos = MouseGetPos()

   MouseMove(MouseGetPos(0)+1,MouseGetPos(1)+1,0)

   Do
   MouseMove(MouseGetPos(0)+1,MouseGetPos(1),0)
   Until PixelGetColor(MouseGetPos(0),MouseGetPos(1)) = 0x000000
   MouseMove(MouseGetPos(0)-1,MouseGetPos(1),0)

   Do
   MouseMove(MouseGetPos(0),MouseGetPos(1)+1,0)
   Until PixelGetColor(MouseGetPos(0),MouseGetPos(1)) = 0x000000
   MouseMove(MouseGetPos(0)+1,MouseGetPos(1),0)

   MouseMove(MouseGetPos(0)+1,MouseGetPos(1)+1,0)

   Local $bPos = MouseGetPos()

   MouseMove($aPos[0],$aPos[1],5)
   MouseDown("left")
   sleep(200)
   MouseMove($bPos[0],$bPos[1],5)
   MouseUp("left")

   sleep(200)
   MouseUp("left")
   sleep(100)

   WinWaitActive("Ankreuzfeld-Eigenschaften")
   ControlClick("Ankreuzfeld-Eigenschaften", "", "Button2")


 EndFunc

Func Terminate()
Exit
EndFunc

 

What it does: First you place the mouse inside a checkbox, then press the key and it will first move to the very left

and then up to determine the starting point, then do the same to set the end-point. Finally drag and drop the checkbox field.

Dunno if this solution is good, but atleast it works. Sadly it's rlly slow, probably cuz it's checking each pixel one by one

whether or not it's black and continue...

 

Is there any way to speed this up? I tried it without moving the mouse, just looking at the pixels, but couldnt get it to

work so I just used the current solution because I didnt have time to figure it out at this point.

(Dont have adobe acrobat pro here, neither am I allowed to install any other programms, autoit portable ftw)

Thanks in advance & best regards,

 

Andrewz

 

Edited by andrewz
Link to comment
Share on other sites

I can appreciate the accuracy required to do this task (measuring pixels), but I'd say one quick way to improve the speed would be to pre-measure the checkbox dimensions.  I'm making an assumption that the checkboxes are standard controls and don't very in shape and size.  Now, the layout and dpi may vary between systems, but hopefully this type if task is a "quick n dirty" solution you only have to run from one machine.

Link to comment
Share on other sites

Hi,

can you post a screenshot to explain the whole workflow?

What do you mean by "really slow"? After placing the mousecursor into a checkbox and pressing the "c"-key, the script is looking for (and find) the borders and finally "drag&drop" within 200milliseconds...

 

 

Link to comment
Share on other sites

I can appreciate the accuracy required to do this task (measuring pixels), but I'd say one quick way to improve the speed would be to pre-measure the checkbox dimensions.  I'm making an assumption that the checkboxes are standard controls and don't very in shape and size.  Now, the layout and dpi may vary between systems, but hopefully this type if task is a "quick n dirty" solution you only have to run from one machine.

​The checkboxes are in fact all the same size, but the checkboxes are widely spread across the pdf, and on top of that I also gotta do textfields which vary in size which makes it impossible to pre measure. And regarding the accuracy, 1-2 pixels too much and it overlaps in the pdf viewer:( Dunno why this program doesnt have the auto selection-wand photoshop has, would be so useful! God thanks I gotta leave a little space to the borders with the textboxes, so I dont have to be as accure as 1 pixel on 800% zoom like I do with the checkboxes. (That's why it's so slow to make checkboxes, gotta view it on 800% zoom to be accure..., same goes to textfields which I view on 100% but they are 10 times bigger.)

 

Hi,

can you post a screenshot to explain the whole workflow?

What do you mean by "really slow"? After placing the mousecursor into a checkbox and pressing the "c"-key, the script is looking for (and find) the borders and finally "drag&drop" within 200milliseconds...

 

 

​I attached a screen of a small part of the document including both check/text boxes. By really slow I mean like 10 - 15 seconds, depending on size.

I'm already done with all the documents by now (actually a few hours after posting the thread), but I was interested in if this could be

solved in a different, + faster way. All I need the script to do is search for two opposing edges in the squares and save the coordinates

for the drag and drop tool. BTW, I don't actually need this anymore *for now*, it's all out of interest!

 

If anyone knows an easier way of coding this, would appreciate any hint :P

Thanks in advance & best regards,

(Excuse my confusing English)

Andrewz

Screen.PNG

Edited by andrewz
Link to comment
Share on other sites

To speed up MouseMove/MouseClick look at my MouseClickFast, MouseMoveFast

 

​Wow thanks! That will probably fix the problem, as I am checking roughly 1000 pixels each run, which leads to a total sleep of 10.000 ?! That's exactly the delay I am talking about! God thanks there are geniuses like you, otherwise I would have never known about the hardcoded sleep nor how to fix it.

Edit: Just realized if I had spent a little more time getting it to work without mousemove (Just checking the variable of the coordinates and look at each pixel by pixel, like "Do variable+1 until pixelgetcolor", I somehow messed up with the array mousegetpos resturns) it would have worked perfectly fine and I wouldnt have the trouble with the harcoded sleep ...

Edited by andrewz
Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...