1

I searched online and all of the answers I found didn't help me. I found this code to be the most helpful to other people:

x, y = win32api.GetCursorPos()

But when I run it, it says "NameError: name 'win32gui' is not defined on line ##"

Why doesn't it work? Should I import a module? I tried to do this:

import win32gui

And it says it's not a module. ("ImportError: No module named win32gui on line ##")

When I searched online I saw that IT IS in fact a module so... what happend?

Tomer Gan
  • 11
  • 1
  • 5

2 Answers2

1

win32gui comes as a part of the external package PyWin32. You may download this package to install this module.

Note that this is not a part of the standart library (a third party library, proceed with caution).

Uriel
  • 13,905
  • 4
  • 21
  • 43
0

You can use a third party module pyautogui, which is installed by: pip install pyautogui

Code for mouse position:

import pyautogui
print pyautogui.position()

It will return a tuple with your x, y coordinate position

Ajax1234
  • 58,711
  • 7
  • 46
  • 83
  • Yeah before I saw this comment I checked online how to install modules and when I open pip3.6.exe it just crashes immediately. Why does it happend? I'm using Windows 7. – Tomer Gan Apr 04 '17 at 17:29
  • Pip should be installed on your machine already since you have python but if not, download the pip package mentioned in the answer to the question here: http://stackoverflow.com/questions/4750806/how-do-i-install-pip-on-windowsrun and then run this command to install pip: python get-pip.py – Ajax1234 Apr 04 '17 at 17:41