Are there any other ways to get the current foregroundwindow without using win32gui(win32gui.GetWindowText (win32gui.GetForegroundWindow()))?
Asked
Active
Viewed 182 times
1
-
Possible duplicate of: [Obtain active window using python](https://stackoverflow.com/questions/10266281/obtain-active-window-using-python), where the python 3 code only uses the built-in `ctypes` library ([solution from Mitch McMabers](https://stackoverflow.com/a/58355052/10961342)). – Thymen May 23 '21 at 22:01
-
saw it but that only gets the pid and not the name – Augurkenplukker12 May 24 '21 at 10:22
-
1When I tested it, the `buff.value` contains the window name. – Thymen May 24 '21 at 11:25
-
ah worked thanks! do you also happen to know why this must be in utf-8. I am trying to write the output to a file and encode it(something simple like base64). But with utf-8 encoding this is impossible (but the file needs utf-8 to write special characters from buff.value output ) – Augurkenplukker12 May 24 '21 at 11:38
-
I am not sure, but I assume that it is because of the `ctypes`. Have you tried it with the `codecs` ([docs](https://docs.python.org/3/library/codecs.html)) library? – Thymen May 24 '21 at 16:21