0

I've been searching the web and StackOverflow for a while now and still can't find an answer to this question. I have an application that I need to set the mouse position for, and I would like it to be cross-platform. I know how to do it in windows:

import ctypes
ctypes.windll.user32.SetCursorPos(x, y)

I need this to work on Linux and OS-X as well. I do not want to install any modules either, just Pure Python. There's something wrong with Pip on my machine and I haven't been able to fix it(but that's a different question).

My question is, how can I make a cross-platform program that allows me to set the mouse cursors position?

Preston Hager
  • 1,514
  • 18
  • 33

1 Answers1

0

I don't think you can.

I haven't been able to find any way to control mouse movement on macOS or Linux without installing modules with pip.

If you do find a way, however, just run this pseudocode:

if platform is Windows:
    import ctypes
    move mouse using ctypes
if platform is Mac:
    import whatever module mac needs
    move mouse using above module
if platform is Linux:
    etc

There are lots of suggested modules in this SO question (scroll past the first couple for more cross-platform solutions). The most common one seems to be pyautogui, but I can't comment on which is best, as I haven't used any.

Have you tried completely removing python/pip from you computer and reinstalling?

Tom Burrows
  • 2,225
  • 2
  • 29
  • 46
  • I haven't removed Pip because I don't know how to uninstall and reinstall it. And thanks for the list, but I've been looking for _Pure Python_ approaches for Mac and Linux. – Preston Hager Jan 16 '17 at 11:09
  • @PrestonHager What platform are you on? If it is mac, I can probably help, but I guess it is windows... – Tom Burrows Jan 16 '17 at 11:11
  • Yes, I'm on windows currently. And I would open a VM for Linux but I can't get those to work either. I think my machine hates me for programming it. :P – Preston Hager Jan 16 '17 at 11:13
  • @PrestonHager I assume you've googled around? You could try to find out where python is kept in your file system, then delete it, or try to use an alternate install of python some other way. If you can't work out anything, then open a question here on SO with what you want, and what you've tried. – Tom Burrows Jan 16 '17 at 17:48
  • As for the Pip issue, I fixed it. I just had to add the `--force-reinstall` and `-I` tags to the command. Thanks for your help, @Gloin. – Preston Hager Jan 16 '17 at 21:13