0

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>
4
  • 1
    Virtually moving mouse cursor is not practical. Have you consider moving the mouse to click and reset back the cursor to its original position ? Commented Oct 21, 2022 at 17:17
  • @rafathasan no I did not, but the issue is in Remote Desktop in fact, that if I close the session, my Python script does not work anymore. But I think if I find a way to only click without moving cursor will solve my problem (testing both in my laptop and server). Commented Oct 21, 2022 at 17:19
  • Where are you running the python script ? In a remote machine ? Commented Oct 21, 2022 at 17:24
  • @rafathasan because I just know Python (at least I can understand it better). If you have any other ways I'll be happy. The way is not important, it only matters that program runs fine. Commented Oct 21, 2022 at 17:28

2 Answers 2

2

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)
Sign up to request clarification or add additional context in comments.

4 Comments

Thanks, but can you give me an example of using Selenium? I think it may help me (combination of pyautogui and selenium).
with selenium you don't need to use mouse. selenium can simulate user behavior using webdrivers like gecko, chromedriver etc. See more selenium
yes I know that, but I need to click using selenium on another position which is not web browsers (suppose I want to use click function of selenium in another application like WhatsApp Desktop or Telegram).
Using selenium is not possible with Desktop application like you said WhatsApp Desktop, Telegram etc. Check out for alternatives like Winium.Desktop, Twin, Jau, White etc. See more can-selenium-be-used-for-desktop-applications
0

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

1 Comment

Please use comment box to say this instead of answering. I need to run an application click on some x,y position and that button does something, but I need to do this clicking very fast as soon as the button is available to click. It's for ordering and purchasing something which is limited to buy.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.