Mouse position combination macro Topic is solved

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
FortniteSpanishGuy
Posts: 15
Joined: 11 Jun 2021, 12:31

Mouse position combination macro

24 Feb 2024, 20:03

My problem is that everything work except when i try to combine P and V because P is not pushing down itself physycally... (only works when i press P with my finger)
Theres any solution?

Code: Select all

loop
{
MouseGetPos, StartVarX, StartVarY
sleep, 100
MouseGetPos, StartVarX, StartVarY
If (StartVarY > CheckVarY)
Send {p down}
If (StartVarY < CheckVarY)
send o
}
esc::exitapp

p & v ::c
o & v::x

[Mod edit: Added [code][/code] tags. Please use them yourself when posting code.]
Last edited by FortniteSpanishGuy on 25 Feb 2024, 12:32, edited 2 times in total.
User avatar
boiler
Posts: 17387
Joined: 21 Dec 2014, 02:44

Re: Mouse position combination macro

24 Feb 2024, 20:26

@FortniteSpanishGuy — Please do not post code again without putting [code][/code] tags around it! Thank you.
User avatar
mikeyww
Posts: 27366
Joined: 09 Sep 2014, 18:38

Re: Mouse position combination macro

24 Feb 2024, 21:04

Hello,

Without a stated goal, there is no stated solution. I recommend providing a detailed description of what the script should do.

Code: Select all

#Requires AutoHotkey v1.1.33

F3::Send {p down}
F6::
Send {p up}
SoundBeep 1000
Return

p::p
p & v::
#If GetKeyState("p")
v::Send c
#If
FortniteSpanishGuy
Posts: 15
Joined: 11 Jun 2021, 12:31

Re: Mouse position combination macro

25 Feb 2024, 10:29

What im trying to do is when i move my mouse up direction{P} i want to press with my finger V and the script send me a C
(or when i move my mouse down direction{O} and pressing with my finger V and the script send me a X)
...is for making a fast action videogame less confusing using less fingers making 2 different results with the same Key)
Last edited by FortniteSpanishGuy on 25 Feb 2024, 12:31, edited 1 time in total.
User avatar
mikeyww
Posts: 27366
Joined: 09 Sep 2014, 18:38

Re: Mouse position combination macro

25 Feb 2024, 10:56

This is probably not what you want, but your description is not clear. The script here sends different text based on whether the mouse is moving upward or downward.

Code: Select all

#Requires AutoHotkey v1.1.33
#InstallMouseHook
idleReset := 300
SetTimer Check, 35
Check:
CoordMode Mouse
last := y
MouseGetPos,, y
Switch {
 Case last = "": Return
 Case A_TimeIdleMouse > idleReset: last := key := ""
 Case y < last: key := "c" ; Moving up
 Case y > last: key := "x" ; Moving down
}
Return

v::Send % key
FortniteSpanishGuy
Posts: 15
Joined: 11 Jun 2021, 12:31

Re: Mouse position combination macro

25 Feb 2024, 11:11

when i execute your code, it says that: Error line 9: "Switch"

im very bad at programming, but that is correct... my description is: when im pressing with my finger V when my mouse is moving foward, the script will send me an C
and when im pressing with my finger V when my mouse is moving backwards, the script will send me an X

making easier to press C and X with only one button (V)
User avatar
mikeyww
Posts: 27366
Joined: 09 Sep 2014, 18:38

Re: Mouse position combination macro

25 Feb 2024, 11:17

I would update AHK to version 1.1.37.01.
  • 1.1.32.00 Fixed Switch treating strings as always true.
  • 1.1.33.11 Fixed Switch { incorrectly raising a load-time error.
  • 1.1.36.00 Changed Switch/Case to perform non-numeric comparison when the switch or case expression is a lone literal string, such as "00", and documented comparison behaviour which was previously undocumented.
  • 1.1.36.01 Fixed undefined behaviour for Switch numeric comparisons.

Code: Select all

#Requires AutoHotkey v1.1.33
#InstallMouseHook
idleReset := 300
SetTimer Check, 35
Check:
CoordMode Mouse
last := y
MouseGetPos,, y
Switch
{
 Case last = "": Return
 Case A_TimeIdleMouse > idleReset: last := key := ""
 Case y < last: key := "c" ; Moving up
 Case y > last: key := "x" ; Moving down
}
Return

v::Send % key
FortniteSpanishGuy
Posts: 15
Joined: 11 Jun 2021, 12:31

Re: Mouse position combination macro

25 Feb 2024, 11:26

wow it works so well! but when my mouse is not moving i cant use V when the script is on...
User avatar
mikeyww
Posts: 27366
Joined: 09 Sep 2014, 18:38

Re: Mouse position combination macro

25 Feb 2024, 11:31

You can set the context for the hotkey.

Code: Select all

#If key
v::Send % key
#If
FortniteSpanishGuy
Posts: 15
Joined: 11 Jun 2021, 12:31

Re: Mouse position combination macro

25 Feb 2024, 11:46

and one last question, if i want to add a certain level of (Y-axis) pixels for example...
i move a litlte the mouse foward, it does not activate C...
but when i move a lot foward, for example: 10 pixels then C activates


you are a hero to me, thank you...
User avatar
mikeyww
Posts: 27366
Joined: 09 Sep 2014, 18:38

Re: Mouse position combination macro

25 Feb 2024, 11:49

The current script determines whether the current y-value differs from the previous y-value. You can instead subtract the two values and then act upon the difference. Increase the timer period if needed.
FortniteSpanishGuy
Posts: 15
Joined: 11 Jun 2021, 12:31

Re: Mouse position combination macro

25 Feb 2024, 12:05

mikeyww wrote:
25 Feb 2024, 11:49
The current script determines whether the current y-value differs from the previous y-value. You can instead subtract the two values and then act upon the difference.
im sorry for being so dumb, but i dont get it...

Code: Select all

 Case y +10 < last: key := "c" ; Moving up
 Case y -10 > last: key := "x" ; Moving down
i just add +10? i feel so ashamed for being so bad at programming
User avatar
mikeyww
Posts: 27366
Joined: 09 Sep 2014, 18:38

Re: Mouse position combination macro  Topic is solved

25 Feb 2024, 12:35

You are on the right track. Does it work? If you write sample values of your variables, you can quickly determine what to change. Another approach is below, though it might not do what you want. The main difference between the scripts is in when the V will be sent. The timer period here has been increased but might be too high or too low.

Code: Select all

#Requires AutoHotkey v1.1.33
#InstallMouseHook
idleReset := 400
minDist   := 10
SetTimer Check, 100
Check:
CoordMode Mouse
last := y
MouseGetPos,, y
Switch
{
 Case last = "": Return
 Case A_TimeIdleMouse > idleReset: last := key := ""
 Case y < last: key := "c" ; Moving up
 Case y > last: key := "x" ; Moving down
}
Return

#If key
v::Send % Abs(y - last) < minDist ? "" : key
#If
You now know how to edit your script and test the revision. Enjoy! :wave:

As you test, you can consider the following contributors to the results.
  1. The timer period
  2. The previous y-value
  3. The current y-value
  4. The value of "key"
  5. Conditions that change the value of "key"
  6. Conditions that change whether the hotkey is triggered
There are various ways to learn these things. You can display values. You can use AHK to list or examine the values. You can use a debugging tool. You can also create your own simulated scenarios to see what would happen in each of them.

Another approach is writing all of the rules in your own (plain) language. You would then translate the rules into AHK code. The main barrier to your success so far has been that you have not decided what you want the rules to be. Nonetheless, you are the person to define them.

Return to “Ask for Help (v1)”

Who is online

Users browsing this forum: No registered users and 400 guests