Reputation: 4133
I tried many answers on stackoverflow and other websites but all of them actually move my mouse cursor.
I'm looking for a way to click in a position (x, y) without actually moving my mouse cursor.
Also I want to run it in a Windows RDP, so that when I exit the RDP, it still runs and clicks on it.
I tried python modules like pyautogui
, mouse
, clickpy
and pymouse
but I failed.
Do you help me for this?
This is my simple HTML/JS code if you intend to test with:
<!DOCTYPE html>
<html>
<head>
<script>
var clicks = 0;
function myFunction() {
clicks += 1;
document.getElementById("demo").innerHTML = clicks;
}
</script>
</head>
<body>
<p>Click the button to trigger a function.</p>
<button onclick="myFunction()">Click me</button>
<p id="demo"></p>
</body>
</html>
Upvotes: 0
Views: 308
Reputation: 572
This doesn't virtually move cursor but logically move the cursor and click then again reset the cursor's position to its original position.
import pyautogui as ag
def clickAndResetCursor(x,y):
i,j = ag.position()
ag.moveTo(x,y)
ag.click()
ag.moveTo(i,j)
Upvotes: 2
Reputation: 65
This is simple impossible, you can not click on something if your mouse doesn't hovers above it. Please tell why you need this so we can think of an other solution
Upvotes: 0