make my mouse draw a picture i gave it?

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
omry1243
Posts: 7
Joined: 14 Nov 2015, 04:39

make my mouse draw a picture i gave it?

14 Nov 2015, 04:48

I am not sure if you are supposed to post this here, i searched for other places on this forum but this place seemed logical, anyway I was searching for a long time for a program that makes my mouse draw a picture i gave it, as in automatically and precisely, i kept on searching until, i found a script here called pixel recreator, the program itself didn't work since it was 4 years old and presumably pretty outdated, anyway if anyone can perhaps create me a script for that or maybe update the old script i would be forever in your favor!, here you go https://autohotkey.com/board/topic/7015 ... -pictures/
User avatar
Blackholyman
Posts: 1293
Joined: 29 Sep 2013, 22:57
Location: Denmark
Contact:

Re: make my mouse draw a picture i gave it?

14 Nov 2015, 05:29

Where and for what are hoping to use this?
Also check out:
Courses on AutoHotkey

My Autohotkey Blog
:dance:
omry1243
Posts: 7
Joined: 14 Nov 2015, 04:39

Re: make my mouse draw a picture i gave it?

14 Nov 2015, 09:12

i just plan to use it on an animation site :P, nothing big
User avatar
Blackholyman
Posts: 1293
Joined: 29 Sep 2013, 22:57
Location: Denmark
Contact:

Re: make my mouse draw a picture i gave it?

14 Nov 2015, 09:58

So how are you hoping for it to work?

How will it pick colors to paint?
Also check out:
Courses on AutoHotkey

My Autohotkey Blog
:dance:
omry1243
Posts: 7
Joined: 14 Nov 2015, 04:39

Re: make my mouse draw a picture i gave it?

14 Nov 2015, 12:09

I don't need colors, as long as it can create the outline of the image I'm fine, it would be nice if you can set the points where it draws though, i don't want it to draw all across my screen, just the region i pick, it isn't necessary though.
John
Posts: 78
Joined: 10 Apr 2014, 08:59

Re: make my mouse draw a picture i gave it?

14 Nov 2015, 12:34

You're still being pretty obscure.
Do you want to translate vectors into mousemoves or do a 1 to 1 trace from a bitmap into another application?
If you want it to actually draw, mouse drags, then the only 'realistic' choice would be using a vector image because a bitmap would require ridiculous amount of preprocessing to determine what to draw and how.

Anyway, try this out, a script i wrote some time ago and see if it does what you want.
It takes in an image (.jpg, .png, etc.) and when it's done scanning it, it'll draw it in mspaint.
Uses 2 colors so pick main and secondary color and be sure to select the pen tool.
"Space" to start the mspaint drawing (click after it's done) and "right shift" to kill the script when you're done or something goes awry.

Code: Select all

SetBatchLines,-1
SetWinDelay,-1
SetMouseDelay,1
fileselectfile,img_src
inputbox,mult,Promptulo,Type in the multiplier to increase/reduce the img size (e.g. 2`, 0.1`, 0.5),, 400,150
gui,add,picture,,% img_src
gui,show,,imgoo
ControlGetPos,x_offset,y_offset,image_width,image_height,Static1,imgoo
image_width := image_width*mult, image_height := image_height*mult
guicontrol,,Static1,*w%image_width% *h%image_height% %img_src%
gui,show,autosize
hDC := DllCall("user32.dll\GetDCEx", "UInt", winactive("a"), "UInt", 0, "UInt", 1|2)
imageArr := {}
tooltip, scanning,0,0
loop % image_height {
	y_index := a_index
	loop % image_width {
		f := DecToHex(DllCall("gdi32.dll\GetPixel", "UInt", hDC, "Int", a_index+x_offset, "Int", y_index+y_offset, "UInt"))
		value := (0xff0000 & f) >> 16
		value += (0x00ff00 & f) >> 8
		value := (value+(0x0000ff & f))/3
		if (value < 180 && value > 80)
			imageArr[a_index,y_index] := 2
		else if (value < 80)
			imageArr[a_index,y_index] := 1
		else
			imageArr[a_index,y_index] := 0
	}
}
tooltip, done,0,0
return

space:: ;draw the image in paint
winactivate,ahk_class MSPaintApp
winwaitactive, ahk_class MSPaintApp
mousegetpos,paint_offset_x,paint_offset_y
loop % image_height {
	y_index := a_index
	loop % image_width {
		
		draw_x := a_index+paint_offset_x
		draw_y := y_index+paint_offset_y
		if (imageArr[a_index,y_index] == "1")
			click left %draw_x%, %draw_y%
		else if (imageArr[a_index,y_index] == "2")
			click right %draw_x%, %draw_y%
	}
}
return

DecToHex(Value){
   oldfrmt := A_FormatInteger
   hex := Value
   SetFormat, IntegerFast, hex
   hex += 0
   hex .= ""
   SetFormat, IntegerFast, %oldfrmt%
   return hex
}
Edit: The best thing would be if you linked to the animation tool and gave a sample of image that you want to appear in that tool.
omry1243
Posts: 7
Joined: 14 Nov 2015, 04:39

Re: make my mouse draw a picture i gave it?

14 Nov 2015, 13:10

Well, i tried your code, i didn't manage to use it though, kept getting stuck at the scanning image part, apart of that it made my spacebar useless, i couldn't add spaces between my sentences so i had to restart xD, other than that im sure thats what i want, there is an old video i saw showing exactly what i want. this is one which im pretty sure wont work nowdays: https://youtu.be/f75CMwvTO4Q?t=2m38s you basically pick a picture and it does as shown, the other video is this https://youtu.be/FC_yrmHXyXA?t=2m35s

thanks for bothering with my nonsense
John
Posts: 78
Joined: 10 Apr 2014, 08:59

Re: make my mouse draw a picture i gave it?

14 Nov 2015, 13:39

It got 'stuck' because 'scanning' the image takes a while when using the method I did. You should give it another go with a smaller multiplier, like 0.2 or 0.1 (200x200 img took like a 30ish secs on my comp with multiplier of 1).
You should change the "space" hotkey to something less obtrusive like "rctrl" or so.
Also to end the script from running, you just have to press the right shift to end it.
If rshift didn't end it, then it means the script froze and that was probably caused by "setbatchlines,-1". If that was the case then increase it to 1 or remove it altogether.

To see how done it is with the scanning, add this line right after the first "loop % image_width {".

Code: Select all

loop % image_width {
	tooltip % "Scanned " round((((y_index-1)*image_width)+a_index)/(image_width*image_width)*100,2) "% of the image." ; <-- add this
	...
omry1243
Posts: 7
Joined: 14 Nov 2015, 04:39

Re: make my mouse draw a picture i gave it?

14 Nov 2015, 14:14

Yes!, that is what i wanted!, the only problem is that it can only do it in paint, is there any way to make it draw in only one color without the right click and outside of paint?, the problem was that some images cant go on a low size like 0.4, they can only go above 1, otherwise they show a really small icon, or maybe im just really dumb, also from what i understood from the code with my very little knowledge, i don't see anything assigned to stopping the script, let alone shift, thanks for helping!
John
Posts: 78
Joined: 10 Apr 2014, 08:59

Re: make my mouse draw a picture i gave it?

14 Nov 2015, 14:21

Just remove the "winactivate" and "winwait" stuff from the "Space" hotkey and it'll start clicking anywhere you like.
Of course you'll have to be careful since the, now posessed mouse, will start clicking the image everywhere.

To only use left click, replace the following..

Code: Select all

if (value < 180 && value > 80)
			imageArr[a_index,y_index] := 2
		else if (value < 80)
			imageArr[a_index,y_index] := 1
		else
			imageArr[a_index,y_index] := 0
with..

Code: Select all

if (value < 80)
			imageArr[a_index,y_index] := 1
As for the size issue, it's a tradeoff between how long you're willing to wait and how big you want. With this script it's either or.
I might have some time later/tomorrow but, for now the above script will have to do.
omry1243
Posts: 7
Joined: 14 Nov 2015, 04:39

Re: make my mouse draw a picture i gave it?

14 Nov 2015, 14:29

The size isn't an issue, you have done more than enough with that :), thanks
omry1243
Posts: 7
Joined: 14 Nov 2015, 04:39

Re: make my mouse draw a picture i gave it?

14 Nov 2015, 15:42

Welp, you gave me exactly what i wanted, and i realized it isn't really gonna work that well with what i am doing, i might keep the script if i will need it, thank you!
chocouy
Posts: 1
Joined: 01 May 2020, 07:57

Re: make my mouse draw a picture i gave it?

01 May 2020, 07:59

hi i apologize for necro posting, but i am having trouble finding out how the script figures out where it starts drawing. i have been reading the manual for a while now and my head is really starting to hurt.

Return to “Ask for Help (v1)”

Who is online

Users browsing this forum: Bobak, mapcarter and 296 guests