Need a very simple macro for work

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
Orfieus
Posts: 6
Joined: 14 Oct 2021, 12:04

Need a very simple macro for work

Post by Orfieus » 14 Oct 2021, 12:34

All I do for work is confirm customer information then push one of 3 buttons. What I would like is when I push a button, say 0, it sends 0 but when I push and hold 0 it does a bunch of MouseMove and Click stuff (I have all the coordinates set as I am using a macro right now that is really cumbersome)

I did some Googling and I found some help but I simply cannot get it to work, this is what I am testing with

Code: Select all

CoordMode Mouse, Screen

0::
	if KeyPressed ; key repeat suppression
		return
	KeyPressed := 1 
	start := 0_Tickcount
	SetTimer, isHeld, -1900
	return
	
0 up::
	SetTimer, isHeld, Off
	KeyPressed := 0
	if (0_Tickcount - start < 400)
		send 0
	return
	
isHeld(){
	send 4
}
My issue with this code is when I push and hold 0 it sends 4 but once I release it sends 0. So push and hold results in "40" instead of just "4". Also I'm not sure how well this will work as I need something for when I push+hold - and =

As for the mouse movements this is what I am using now when I want to transfer someone (the transfer button moves on the screen so I have to click in 3 different spots to ensure I hit the button),

Code: Select all

MouseGetPos x, y
MouseMove 2051, -55
Click
MouseMove 2051, -100
Click
MouseMove 2051, -135
Click
MouseMove % x, % y
I don't think what I am asking is overly complicated I simply don't have the knowledge to put it all together

Rohwedder
Posts: 7655
Joined: 04 Jun 2014, 08:33
Location: Germany

Re: Need a very simple macro for work

Post by Rohwedder » 14 Oct 2021, 15:04

Hallo,
try:

Code: Select all

CoordMode Mouse, Screen

0::
	if KeyPressed ; key repeat suppression
		return
	KeyPressed := 1 
	start := A_Tickcount
	SetTimer, isHeld, -1900
	return
	
0 up::
	SetTimer, isHeld, Off
	KeyPressed := 0
	if (A_Tickcount - start < 400)
		send 0
	return
	
isHeld(){
	send 4
}

Orfieus
Posts: 6
Joined: 14 Oct 2021, 12:04

Re: Need a very simple macro for work

Post by Orfieus » 14 Oct 2021, 19:38

That absolutely fixed my double press issue but when I try to make one for = I hit an error,

Code: Select all

CoordMode Mouse, Screen

0::
	if KeyPressed ; key repeat suppression
		return
	KeyPressed := 1 
	start := A_Tickcount
	SetTimer, isHeld, -1900
	return
	
0 up::
	SetTimer, isHeld, Off
	KeyPressed := 0
	if (A_Tickcount - start < 400)
		send 0
	return
	
isHeld(){
	send 4
}


=::
	if KeyPressed ; key repeat suppression
		return
	KeyPressed := 1 
	start := A_Tickcount
	SetTimer, isHeld, -1900
	return
	
= up::
	SetTimer, isHeld, Off
	KeyPressed := 0
	if (A_Tickcount - start < 400)
		send =
	return
	
isHeld(){
	send 5
}

Rohwedder
Posts: 7655
Joined: 04 Jun 2014, 08:33
Location: Germany

Re: Need a very simple macro for work

Post by Rohwedder » 15 Oct 2021, 01:00

The 0 and = blocks need their own variables and functions.
Try:

Code: Select all

CoordMode Mouse, Screen
0::
if ZeroStart ; key repeat suppression
	return
ZeroStart := A_Tickcount
SetTimer, ZeroIsHeld, -1900
return
0 up::
SetTimer, ZeroIsHeld, Off
if (A_Tickcount - ZeroStart < 400)
	send 0
ZeroStart := 0
return
ZeroIsHeld()
{
	send 4
}
=::
if EqualStart ; key repeat suppression
	return
EqualStart := A_Tickcount
SetTimer, EqualIsHeld, -1900
return
= up::
SetTimer, EqualIsHeld, Off
if (A_Tickcount - EqualStart < 400)
	send {=} ;needs braces
EqualStart := 0
return
EqualIsHeld()
{
	send 5
}

Orfieus
Posts: 6
Joined: 14 Oct 2021, 12:04

Re: Need a very simple macro for work

Post by Orfieus » 15 Oct 2021, 10:50

I copied and pasted the above script and I am still hitting an error

Orfieus
Posts: 6
Joined: 14 Oct 2021, 12:04

Re: Need a very simple macro for work

Post by Orfieus » 20 Oct 2021, 07:05

Can anyone help me out here or is what I want really complicated?

amateur+
Posts: 655
Joined: 09 Oct 2021, 15:43

Re: Need a very simple macro for work

Post by amateur+ » 20 Oct 2021, 07:58

Orfieus wrote: CoordMode Mouse, Screen
MouseMove 2051, -55
Why do you use negative coordinates with CoordMode Mouse, Screen? It will move the cursor to (2051, 0).
Insead of hotkeys "short 0" and "long pressed 0" use different keys such as 0 and 1 or 0 and ^0.

Post Reply

Return to “Ask for Help (v1)”