Involuntary straight line Topic is solved

Get help with using AutoHotkey (v2 or newer) and its commands and hotkeys
diegg1739
Posts: 118
Joined: 17 Oct 2023, 18:29

Involuntary straight line

28 Mar 2024, 18:38

Hi, I use the following script to select colors using F4 to F12 keys in Paint.net application.

Code: Select all

#Requires AutoHotkey v2.0
#SingleInstance
Persistent
#HotIf WinActive('ahk_exe paintdotnet.exe')
F4::
	{
		MouseGetPos &xpos, &ypos
		Click 1147, 622     ; Negro
		MouseMove xpos, ypos
	}
F5::
	{
		MouseGetPos &xpos, &ypos
		Click 1196, 622     ; Naranja
		MouseMove xpos, ypos
	}
F6::
	{
		MouseGetPos &xpos, &ypos
		Click 1244, 622    ; Celeste
		MouseMove xpos, ypos
	}
F7::
	{
		MouseGetPos &xpos, &ypos
		Click 1185, 622    ; Rojo
		MouseMove xpos, ypos
	}
F8::
	{
		MouseGetPos &xpos, &ypos
		Click 1172, 622     ; Gris
		MouseMove xpos, ypos
	}
F9::
	{
		MouseGetPos &xpos, &ypos
		Click 1208, 622    ; Amarillo
		MouseMove xpos, ypos
	}
F10::
	{
		MouseGetPos &xpos, &ypos
		Click 1232, 622    ; Verde
		MouseMove xpos, ypos
	}

F11::
	{
		MouseGetPos &xpos, &ypos
		Click 1256, 622    ; Azul
		MouseMove xpos, ypos
	}
F12::
	{
		MouseGetPos &xpos, &ypos
		Click 1268, 622    ; Violeta
		MouseMove xpos, ypos
	}
The colors are located in a subwindow of Paint.net called "Colors", as seen in the image below. There is also the AHK Spy window that displays the data from the "Colors" subwindow.
Ventana Pain.net.png
Ventana Pain.net.png (188.7 KiB) Viewed 497 times
[/url]
I have the following problem: When using stylus and tablet, pressing a key to select the color draws a straight line from the stylus position to where AHK clicks. This occurs without the stylus being in contact with the tablet. I even moved the stylus 1.5 cm = 0.6 inches away from the tablet, and the line is drawn.
If I replace the stylus with the mouse and type F4/F12 to select the color, the straight line is not drawn. That's why I think it may be some problem with the stylus or the tablet, because it started happening a few days ago. I changed the stylus lead because it was worn out, but the problem didn't solve.
I've been using this AHK script for months. I added BlockInput to the script (I don't know if correctly), but it didn't fix the problem.
Is there a way to modify the script so that that straight line is not drawn? Thank you so much.
User avatar
mikeyww
Posts: 28989
Joined: 09 Sep 2014, 18:38

Re: Involuntary straight line

28 Mar 2024, 19:20

I have not tested this, but you can try various approaches and workarounds. Examples would be adding sleep, increasing the mouse delay, or sending the button up before the move. You might also want to have a look at other posts about touchpads or touchscreens. I do not know whether this applies here, but my recollection is that mouse buttons or a stylus works differently on touchscreens, as these might actually activate on release instead of press, or vice-versa. Some experimentation may be in order.
Rohwedder
Posts: 7904
Joined: 04 Jun 2014, 08:33
Location: Germany

Re: Involuntary straight line

29 Mar 2024, 03:38

Hallo,
use the hexadecimal input Más >>
and place the cursor once in the input field.

Code: Select all

#HotIf WinActive('ahk_exe paintdotnet.exe')
F4::Send "^a000000" ; negro
F7::Send "^aFF0000" ; rojo
diegg1739
Posts: 118
Joined: 17 Oct 2023, 18:29

Re: Involuntary straight line

29 Mar 2024, 10:41

Hello. Hex input didn't work.
Reading the documentation I am not moving anywhere. Any option or command I try doesn't work or gives an error. I used BlockInput, BlockInput SendMouse, but it gives error. The documentation is confusing for me as a beginner.
My idea is that when I press F4/F12 to select the color, the stylus (or mouse) pointer is automatically disabled, so as not to interfere with the AHK click that selects the color.
I need some script snippets to test and see if any of them might work.
Another option is that you can change color without clicking. It will be possible? Thanks for any help you can give me.
Rohwedder
Posts: 7904
Joined: 04 Jun 2014, 08:33
Location: Germany

Re: Involuntary straight line

29 Mar 2024, 11:55

Change color without clicking, that's exactly what I'm trying to do!
First try without the pen and the tablet to see if this script writes the hex color. You must first write something manually in this field so that the write cursor (caret) is placed in the correct position:

Code: Select all

#Requires AutoHotkey v2.0
#HotIf WinExist("Colores ahk_exe paintdotnet.exe")
F4::Color("000000") ; negro
F7::Color("FF0000") ; rojo
#HotIf
Color(C) {
	WinActivate "Colores ahk_exe paintdotnet.exe"
	Send "^a{Bs}" ; delete old hex color
	Sleep(100)
	Send C ; write new hex color
}
diegg1739
Posts: 118
Joined: 17 Oct 2023, 18:29

Re: Involuntary straight line

29 Mar 2024, 12:44

I tested the script and these are the results:
Pressing F4 or F7 colors the entire Paint.net sheet with the current color. Will this happen because in Paint.net, ^a (Control a) is for selecting everything?
Rohwedder
Posts: 7904
Joined: 04 Jun 2014, 08:33
Location: Germany

Re: Involuntary straight line

29 Mar 2024, 13:42

Usually (not only in Paint.net) ^a (Control a) does not select 'everything i.e. heaven and earth' but 'everything in the active area'. If you ignore this hint:
"You must first write something manually in this field so that the write cursor (caret) is placed in the correct position", an incorrect area is active and something wrong is selected. I just want to select the whole content of the hex color control so that the following {Bs} (= BackSpace) deletes the old hex color.
I used the pen tool and was able to change the pen color at will with that script.
diegg1739
Posts: 118
Joined: 17 Oct 2023, 18:29

Re: Involuntary straight line

29 Mar 2024, 14:41

I think I'm not understanding. When you say "you must manually type something into this field." What field are you referring to? Because if I write a word, with the keyboard, using the TEXT tool on the Paint.net sheet and then press F4, the entire sheet is colored with active color.
If I mouse-click the PEN tool, then click the COLORS window to make it active, and then press F4 it colors the entire Paint.net sheet in the active color (whatever the color is). What am I doing wrong?
Rohwedder
Posts: 7904
Joined: 04 Jun 2014, 08:33
Location: Germany

Re: Involuntary straight line  Topic is solved

30 Mar 2024, 04:52

I had referring to this field:
this field.png
this field.png (41.75 KiB) Viewed 346 times
But all this should be a thing of the past.
Now, the only prerequisite is that the Colors Window is available in its, above shown, extended form
Try:

Code: Select all

#Requires AutoHotkey v2.0
Colors_Window := "Colores ahk_exe paintdotnet.exe" ; Spain
; Colors_Window := "Farben ahk_exe paintdotnet.exe" ; Germany
#HotIf WinExist(Colors_Window)
F4::Color("000000") ; negro
F7::Color("FF0000") ; rojo
#HotIf
Color(C) {
	Global Colors_Window
	; Calculate ClassNN  of the input field for the hexadecimal color code
	ClassNN := StrReplace(WinGetClass(Colors_Window), "Window.8", "Edit") "4"
	ControlSetText C, ClassNN, Colors_Window ; write new hex color
}
Edit: Colors Window extended or not, the script doesn't care.
Last edited by Rohwedder on 30 Mar 2024, 11:06, edited 1 time in total.
diegg1739
Posts: 118
Joined: 17 Oct 2023, 18:29

Re: Involuntary straight line

30 Mar 2024, 07:41

Perfect Rohwedder!! It works just as I wanted. I completed the script with the other colors and everything goes excellent and fast. I already tried with the stylus active, typing quickly from F4 to F12, and no straight lines are drawn.
Thank you very much for your help and patience! Many greetings :thumbup:
diegg1739
Posts: 118
Joined: 17 Oct 2023, 18:29

Re: Involuntary straight line

30 Mar 2024, 13:18

Indeed Rohwedder, the script works with the COLORS window extended or not.
Thank you again!
diegg1739
Posts: 118
Joined: 17 Oct 2023, 18:29

Re: Involuntary straight line

30 Mar 2024, 13:22

I also thank mikeyww for his collaboration, who has helped me on many occasions. In fact, several of the scripts that I have in optimal working order on my PC were authored by him.

Return to “Ask for Help (v2)”

Who is online

Users browsing this forum: Descolada, Sacho and 38 guests