Hello all, I am appealing the good folks on this forum for help.
I am hoping someone could assist me in the final part of my script.
The script is meant for FPS games. The script reads object coordinate data and then moves the mouse towards those coordinates. It works when I am on the desktop, for instance, while watching gameplay footage. However, when in the actual game, there is no movement (except in the menu where there is a mouse cursor). If I alt-tab the game/put it into window mode where the mouse cursor overlays the game window, it follows the target relatively as expected. Improvements in that area can be implemented if or when actual FOV/aim movement is implemented.
I understand that game engines process inputs from the mouse differently than desktop applications do. I have made and used different AHK scripts in FPS games. It seems that its the DLLCall mouse_event function works, however, not when it comes to absolute measurements, but that seems to be required to produce proper measurements.
Below is my code so far. Any assistance in this would be greatly appreciated
I am hoping someone could assist me in the final part of my script.
The script is meant for FPS games. The script reads object coordinate data and then moves the mouse towards those coordinates. It works when I am on the desktop, for instance, while watching gameplay footage. However, when in the actual game, there is no movement (except in the menu where there is a mouse cursor). If I alt-tab the game/put it into window mode where the mouse cursor overlays the game window, it follows the target relatively as expected. Improvements in that area can be implemented if or when actual FOV/aim movement is implemented.
I understand that game engines process inputs from the mouse differently than desktop applications do. I have made and used different AHK scripts in FPS games. It seems that its the DLLCall mouse_event function works, however, not when it comes to absolute measurements, but that seems to be required to produce proper measurements.
Below is my code so far. Any assistance in this would be greatly appreciated
CODE:
; Function to move the mouse cursor smoothly to a specific position on the screen
SmoothMoveMouseTo(targetX, targetY) {
; Get the current mouse position
MouseGetPos, startX, startY
; Define the number of steps for interpolation
steps := 20
; Calculate the step size for x and y
stepX := (targetX - startX) / steps
stepY := (targetY - startY) / steps
; Smoothly move the mouse cursor to the target position
Loop, % steps {
newX := startX + A_Index * stepX
newY := startY + A_Index * stepY
DllCall("mouse_event", UInt, 1, Int, newX - startX, Int, newY - startY, UInt, 0, UInt, 0)
Sleep, 20 ; Adjust this value for the smoothness of movement
}
}
; Function to move the mouse cursor to a specific position on the screen (absolute)
MoveMouseToAbsolute(x, y) {
Static SysX := 0x10000/A_ScreenWidth, SysY := 0x10000/A_ScreenHeight
; Calculate the absolute coordinates
xa := Ceil(x * SysX)
ya := Ceil(y * SysY)
; Move the mouse using mouse_event function, 0x8001: ABSMOVE
DllCall("mouse_event", "UInt", 0x8001, "UInt", xa, "UInt", ya)
}
; Function to read coordinates from the named pipe
ReadCoordinatesFromPipe() {
; Create named pipe handle
pipe := DllCall("CreateFile", "Str", "\\.\pipe\SamplePipe", "UInt", 0xC0000000, "UInt", 3, "Ptr", 0, "UInt", 3, "UInt", 0, "Ptr", 0)
; Check if the pipe was opened successfully
if (pipe = -1) {
MsgBox, Failed to connect to named pipe.
ExitApp
}
; Infinite loop to read coordinates from the pipe
Loop {
VarSetCapacity(data, 8)
; Check if there is data available in the pipe
DllCall("PeekNamedPipe", "Ptr", pipe, "Ptr", 0, "UInt", 0, "Ptr", 0, "PtrP", bytesAvailable, "Ptr", 0)
; Read data from the pipe if available
if (bytesAvailable > 0) {
; Read the data from the pipe
bytesRead := DllCall("ReadFile", "Ptr", pipe, "Ptr", &data, "UInt", 8, "Ptr", 0, "UInt", 0)
; Check if data was read successfully
if (bytesRead > 0) {
; Extract x and y coordinates from the data
x := NumGet(data, 0, "Int")
y := NumGet(data, 4, "Int")
; Move the mouse to the retrieved coordinates
MoveMouseToAbsolute(x, y)
; Show tooltip with target coordinates
Tooltip, Target coordinates:`nX: %x%`nY: %y%
} else if (bytesRead < 0) {
MsgBox, Error reading from named pipe.
ExitApp
}
}
; Sleep for a short duration before checking again
Sleep, 100
}
}
; Start reading coordinates from the named pipe
ReadCoordinatesFromPipe()
; Hotkeys for Control
Pause:: Pause
^Esc:: ExitApp
Statistics: Posted by prototype_zero — Today, 16:49