I found this solution for pressing virtual keys: https://stackoverflow.com/a/10441322/3448364 But, problem is that VK_SLEEP not working for me. I tried with all other VK_ keys (like VK_VOLUME_UP, VK_MEDIA_NEXT_TRACK...) and it works, only VK_SLEEP not working. This is my code:
VK_SLEEP = 0x5F
hwcode = win32api.MapVirtualKey(VK_SLEEP, 0)
win32api.keybd_event(VK_SLEEP, hwcode)
When I execute that code, nothig happens. When I change virtual key to ie. VK_VOLUME_UP: works like a charm! So, code is OK, but for some reason script won't put PC in sleep with VK_SLEEP. This is source for VK_ codes that I use: https://docs.microsoft.com/en-us/windows/desktop/inputdev/virtual-key-codes
Just to be clear: my keyboard doesn't have dedicated Sleep button. But, doesn't have "volume up" too, and 0xAF (vlume_up) works. So, I don't think problem is keyboard (it's CM MK750).