1

I found this code to be the most helpful to other people:

x, y = win32api.GetCursorPos()

When I run this code, I get an error "NameError: name 'win32gui' is not defined on line ##".

When trying to import the module:

import win32gui

I get an error "ImportError: No module named win32gui on line ##".

I tried running:

pip install win32gui

But it doesn't seem to work. How can I use win32gui?

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
  • 15,579
  • 6
  • 25
  • 46
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
  • 69,937
  • 8
  • 61
  • 102
  • 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