0

I'm bored and just making something for the heck of it in Python. I saw someone typing with spaces between all their letters and decided to make a python script that does this. It was pretty easy, but then I wanted to take it a step further, because copy/pasting from console takes time, so I want to have this script put spaces after every keyboard press but only when I have Discord as the active window. The only things I could find that could give you the active window are from 5-15 years ago, and are all outdated. They say use win32gui, and I pipinstalled it, but it doesn't seem to work.

EDIT: For clarification, I ran "pip install win32gui" and it installed, I opened a python shell and typed "import win32gui" and it said no such module I looked through the modules and found win32 and according to the help command win32gui is part of its package, so I tried win32.win32gui and it says there's no such attribute

I'm new to coding, I'm not entirely sure what I'm doing.

K.Dᴀᴠɪs
  • 9,945
  • 11
  • 33
  • 43
VyleKyle
  • 1
  • 2
  • If this is on [so] you may want to link it to show your research effort. – user202729 Mar 02 '18 at 06:14
  • Does [this](https://stackoverflow.com/questions/10266281/obtain-active-window-using-python) help? – user202729 Mar 02 '18 at 06:15
  • seen that one, it also uses win32gui. "pip install win32gui" works but from what I can tell, you can't import it after doing so. EDIT: In shell if I do "help("win32")" win32gui shows as part of the package contents, but I still can't really seem to touch it in any way. – VyleKyle Mar 02 '18 at 06:24
  • Specify your precise question. What command(s) have you tried and what error(s) does the `import win32gui` statement (or something like that) gives you? – user202729 Mar 02 '18 at 06:25
  • Does [this](https://stackoverflow.com/questions/20113456/installing-win32gui-python-module) help? If it doesn't work you may want to add information in your question - what commands have you typed and etc. – user202729 Mar 02 '18 at 06:27
  • "import win32gui" gives no such module error, win32.win32gui says no such attribute – VyleKyle Mar 02 '18 at 06:27
  • Please [edit] information (necessary for other users to answer) into the question. – user202729 Mar 02 '18 at 06:29
  • Nowadays you can pip install PyWin32 (the package that has `win32gui`) as the package "pypiwin32". You could also use ctypes for this. – Eryk Sun Mar 02 '18 at 09:30
  • How do I use ctypes for this though? – VyleKyle Mar 02 '18 at 15:57
  • Please do not add the solution to your question. If you found a solution that worked best for you, then you can accept it below or answer your own question. This site encourages multiple solutions from other users, as the one that worked best for you may not work the best for someone else. Your question has been rolled back to its previous state. For more information, please visit the [help]. – K.Dᴀᴠɪs Mar 02 '18 at 16:58
  • Possible duplicate of [Obtain Active window using Python](https://stackoverflow.com/questions/10266281/obtain-active-window-using-python) – user202729 Jun 03 '23 at 03:00

1 Answers1

0

It seems win32gui isn't recognized in shell which I was using to test if it worked or not, however after just adding it to an actual python script it works just fine.

VyleKyle
  • 1
  • 2