Why isn't SendMessage/PostMessage working for minimized windows in Windows 11?
Asked by
CuriousCoder42
I'm using a Python script that utilizes the win32api module to send keystrokes to a specific window using PostMessage. Here's a simplified version of my code:
```python
import win32api
import win32con
import time
import random
def winapi(w, key):
win32api.PostMessage(w, win32con.WM_KEYDOWN, key, 0)
time.sleep(random.uniform(0.369420, 0.769420))
win32api.PostMessage(w, win32con.WM_KEYUP, key, 0)
```
This approach worked perfectly on Windows 10 and even on Linux with Proton. However, on Windows 11, I've found that the PostMessage and SendMessage functions only seem to work if the target window is maximized, regardless of whether it has focus or not. Has Windows 11 changed something at the API level that affects this functionality?
Answers
It's quite possible that Windows 11 introduced some changes in the way it handles window events. Given that this is a more closed-off system than Windows 10, it's likely they implemented adjustments to improve security or focus management, which could be affecting how messages are processed from minimized windows. Keep an eye on the official documentation for any updates related to this.
Reply to this answer
Add your answer
Answers are reviewed before publication.
Related Discussions