File: sumo.pyw 1 #!/usr/bin/python3 2 3 # The MIT License (MIT) 4 # 5 # Copyright © 2024 pacman64 6 # 7 # Permission is hereby granted, free of charge, to any person obtaining a copy 8 # of this software and associated documentation files (the “Software”), to deal 9 # in the Software without restriction, including without limitation the rights 10 # to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 11 # copies of the Software, and to permit persons to whom the Software is 12 # furnished to do so, subject to the following conditions: 13 # 14 # The above copyright notice and this permission notice shall be included in 15 # all copies or substantial portions of the Software. 16 # 17 # THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 18 # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 19 # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 20 # AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 21 # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 22 # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 23 # SOFTWARE. 24 25 26 # sumo 27 # 28 # SUspend MOnitor puts the main monitor into its suspended state, making it 29 # all black. Pressing anything on the keyboard or moving the mouse will bring 30 # the monitor's contents back. 31 # 32 # This script only works on Windows. 33 34 35 from sys import argv, exit, stderr 36 37 38 info = ''' 39 sumo 40 41 SUspend MOnitor puts the main monitor into its suspended state, making it 42 all black. Pressing anything on the keyboard or moving the mouse will bring 43 the monitor's contents back. 44 45 This script only works on Windows. 46 '''.strip() 47 48 # a leading help-option arg means show the help message and quit 49 if len(argv) > 1 and argv[1].lower() in ('-h', '--h', '-help', '--help'): 50 print(info, file=stderr) 51 exit(0) 52 53 54 try: 55 from ctypes import windll 56 except: 57 print('this script only works on windows', file=stderr) 58 exit(1) 59 60 try: 61 u = windll.user32 62 desktop = u.GetShellWindow() 63 system_command = 0x0112 64 monitor_power = 0xf170 65 monitor_on = -1 66 monitor_off = 2 67 u.SendMessageW(desktop, system_command, monitor_power, monitor_off) 68 except: 69 print('failed to suspend the main monitor', file=stderr) 70 exit(1)