How to Teleport a mouse (not MouseMove) in ahk? - autohotkey

I am trying to play games using a remote desktop software called rustdesk and I have created a script to move mouse 360 degrees in horizontal manner but as soon as the mouse goes from left to right the character in the game also moves so how to MoveMouse without seeing those changes in rustdesk.
This is the code:
#Persistent
SetTimer, check, -100
return
check(){
If edge("left")
{
MouseMove, 1718, 490, 0
}
else if edge("right")
{
MouseMove, 0, 490, 0
}
; ...
SetTimer, check, -100
}
edge(pos){
SysGet, VirtualWidth, 78
SysGet, VirtualHeight, 79
T := 10
CoordMode, Mouse, Screen
MouseGetPos, mX, mY
left := (mX < T)
top := (mY < T)
right := (mX > VirtualWidth - T)
bottom := (mY > VirtualHeight - T)
If (pos = "left")
return left
else if (pos = "top")
return top
else if (pos = "right")
return right
else if (pos = "bottom")
return bottom
}
I tried using BlockInput but it completely stops the mouse.

Related

Moving the cursor to a specified position as soon as it touches right edge of screen using autohotkey?

I have written code to change mouse position when it touches the left edge of screen
sysget, var_, monitorworkarea
gui, color, 0x000000
gui, +alwaysontop +toolwindow -caption
gui, show, w1 h%var_bottom% x0 y0, left_win
winset, transparent, 1, left_win
onmessage(0x200, "edge")
return
edge()
{
static countdown := 0
if (countdown = 0)
{
settimer, check, -100
countdown := 1
}
return
check:
{
mousegetpos, , , win
wingettitle, title, ahk_id %win%
if (title = "left_win")
{
MouseMove, 960, 300, 0
}
countdown := 0
}
return
}
but it doesn't work if I replace left with right for right edge of screen How do I fix this ?
Try this
#Persistent
SetTimer, check, -100
return
check(){
If edge("left")
{
MouseMove, 960, 300, 0
Send #x
}
else if edge("right")
{
MouseMove, 960, 300, 0
Run Notepad
}
; ...
SetTimer, check, -100
}
edge(pos){
SysGet, VirtualWidth, 78
SysGet, VirtualHeight, 79
T := 10
CoordMode, Mouse, Screen
MouseGetPos, mX, mY
left := (mX < T)
top := (mY < T)
right := (mX > VirtualWidth - T)
bottom := (mY > VirtualHeight - T)
If (pos = "left")
return left
else if (pos = "top")
return top
else if (pos = "right")
return right
else if (pos = "bottom")
return bottom
}

AHK PixelSearch Loop

I'm trying to get my AHK Script to Work.
Basically i want to find a row of x Pixels with the Color 0x26FDFD (BGR). But i don't know the AHK Scripting language well wnough to think about a smart, clean and easy way to program that loop, that the starting point will be modified based on the last found coordinates.
However, here's what i got so far:
SysGet, VirtualWidth, 78
SysGet, VirtualHeight, 79
;Farbe nach der gesucht wird:
ColorVar := 0x26FDFD
i:=0
while i < 10
{
PixelSearch, FoundX, FoundY, 0, 0, VirtualWidth, VirtualHeight, %ColorVar%, 3, Fast
if (ErrorLevel = 2)
{
MsgBox Could not conduct the search.
return
}
else if (ErrorLevel = 1)
{
MsgBox Color could not be found on the screen.
return
}
else
{
MouseMove, %FoundX%, %FoundY%
MsgBox Found a Pixel at %FoundX%x%FoundY%.
;return
}
i++
}
Kinda stupid and basic question, but somehow i can't figure it out.
I just needed to store the X and Y coordinates at the end of each loop, then set the new startpoint accordingly.
here's the code:
i:=0
while i < 5
{
PixelSearch, FoundX, FoundY, startX%A_Index%, startY%A_Index%, VirtualWidth, VirtualHeight, %ColorVar%, 3, Fast
Switch ErrorLevel
{
Case 1:
MsgBox Website ueberpruefen!
return
Case 2:
MsgBox Makro ueberpruefen!
return
Default:
MouseMove, %FoundX%, %FoundY%
;MsgBox Found a Pixel at %FoundX%x%FoundY%.
nextLoop := A_Index + 1
startX%nextLoop% := FoundX + 1
startY%nextLoop% := FoundY
}
i++
}
;msgbox % "found 5 matches!, first at: " startX2 "x" startY2
return

AHK Script to send different button with each successive press

Okay so I wrote this script in AHK to press 2 on the first press of the mouse button and 3 on the second and so on, yet it doesnt work. Any ideas why ?
XButton1::Send, 1;
XButton2::
x:=1
if (x = 1){
Send, 2
x+=1
} else if (x = 2) {
Send, 3
x+=1
} else if (x = 3) {
Send, 4
x+=1
} else if (x = 4) {
Send, 5
x = x - 3
}
Everytime you press XButton2, you reset the value of x to 1....x:=1. So it will obviously only send 2. You need to set the value of x outside of XButton2. This will work:
x := 1
XButton2::
x += 1
SendInput, %x%
return

Autohotkey: How to program to walk in 2D game

I'm writing a macro for a 2D game. The coordinates for the character are given, in (x,y). There are obstacles in the game, so I need to program in a way that the character moves around it.
So I've written a program that reads the memory of x and y coordinates of the game. Then I wrote a function that moves the character to a desired position. The logic is: if x coordinate is less than the desired position, keep moving right, and vice versa. Then, if y coordinate is less than the desired position, keep moving up, and vice versa.
However, because of the obstacles, I have to manually give the coordinates to move to. For example, if I was at (1,1), and told the character to move to (5,5), there might be an obstacle at (3,1) and the character will get stuck. So I'll tell it to move to (1,3) first, then move to (5,3), then (5,5).
I'm just confused on how to SEQUENTIALLY tell the character to move. AFTER I move to (1,3), move to (5,3), then (5,5).
This is what I have:
f1::
WinGetTitle, ai, A
curX := ReadMemory(0x10F6A7D0, ai)
curY := ReadMemory(0x10F6A7D4, ai)
MoveTo(21,13)
if(curX == 21 && curY == 13){
MoveTo(21,28)
}
return
q::
Pause
return
ReadMemory(MADDRESS,PROGRAM)
{
winget, pid, PID, %PROGRAM%
VarSetCapacity(MVALUE,4,0)
ProcessHandle := DllCall("OpenProcess", "Int", 24, "Char", 0, "UInt", pid, "UInt")
DllCall("ReadProcessMemory","UInt",ProcessHandle,"UInt",MADDRESS,"Str",MVALUE,"UInt",4,"UInt *",0)
Loop 4
result += *(&MVALUE + A_Index-1) << 8*(A_Index-1)
return, result
}
MoveTo(targetX,targetY)
{
xadd = 0x10F6A7D0
yadd = 0x10F6A7D4
WinGetTitle, ai, A
Loop{
curX:= ReadMemory(xadd,ai)
curY:= ReadMemory(yadd,ai)
if(curX < targetX){
ControlSend,, {Right}, %ai%
}
else if(curX > targetX){
ControlSend,, {Left}, %ai%
}
else if(curY < targetY){
ControlSend,, {Down}, %ai%
}
else if(curY > targetY){
ControlSend,, {Up}, %ai%
}
Sleep, 30
Okay, so I solved my problem. I just had to make a while-loop in the MoveTo function and terminate it once I reach the position.
MoveTo(targetX,targetY)
{
xadd = 0x10F6A7D0
yadd = 0x10F6A7D4
WinGetTitle, ai, A
isThere := 1
while(isThere = 1){
curX:= ReadMemory(xadd,ai)
curY:= ReadMemory(yadd,ai)
if(curX < targetX){
ControlSend,, {Right}, %ai%
}
else if(curX > targetX){
ControlSend,, {Left}, %ai%
}
else if(curY < targetY){
ControlSend,, {Down}, %ai%
}
else if(curY > targetY){
ControlSend,, {Up}, %ai%
}
if(curX = targetX && curY = targetY){
isThere = 0
}
Sleep, 30

How to input (Holding LButton)?

I am trying to make (Holding down the left button for 1s) to make it do a right click. Here's what i got:
LButton::
MouseClick, right, , , 1, 0, D
Sleep 0
MouseClick, right, , , 1, 0, U
return
How to change the "LButton" input into "Hold LButton for 1 second"?
How about this...
LButton::
StartTime := A_TickCount ; Set the timer
KeyWait, LButton ; Wait for release of mousebutton
ElapsedTime := A_TickCount - StartTime ; Calculate elapsed time
if (ElapsedTime > 1000)
Click, Right ; when longer than 1000 ms
Click, Left ; when shorter than 1000 ms
return
The disadvantage is that you can't use the mouse for e.g. highlighting text anymore...
Here you go:
#Persistent
#SingleInstance Force
#NoEnv
SetBatchLines, -1
global timeDown = 0
SetTimer, checkLeftClick,25
checkLeftClick:
if( GetKeyState("LButton" , "P") )
{
timeDown += 25
}
else
{
timeDown = 0
}
if(timeDown > 1000)
{
MouseClick , left , , , , ,U
Click,Right
timeDown = 0
}
return