Do you have any idea of how to turn on monitor by python code from power saving mode in window 10?
I tried..
- change settings regarding power saving mode
- task scheduler (also checked the option that terminates sleep mode to execute the task)
- wake up program (https://www.codeproject.com/articles/49798/wake-the-pc-from-standby-or-hibernation)
- pyautogui (by moving mouse cursor several times)
- created a bat file and ran it
but failed.
What I am trying to do is to wake up window from power-saving mode, open another program using python, log-in, find a specific chat room and send a message. I used pyautogui.
It was confirmed that the code works fine when the window is not in sleep mode. And it also seems that the program runs okay even when the monitor is off but, the code was not able to doubleClick the icon that was pointed with specific x, y coordinates within the code.
The below is the code.
## v 1.0.0 ##
import schedule
import pyautogui as pg
import time
import pyperclip
import os
nl = '\n'
decider = True
month = time.strftime('%m', time.localtime(time.time()))
day = time.strftime('%d', time.localtime(time.time()))
week = ['월요일 입니다.', '화요일, 락스타 데이 입니다.', '수요일 입니다.', '목요일, 락스타 데이 입니다.', '금요일 입니다.', '토요일 입니다.', '일요일 입니다.']
day_of_theweek = week[time.localtime().tm_wday]
def auto_daily_check():
print("You are not who you think you are.")
global decider
pg.moveTo(1848, 334)
pg.doubleClick()
time.sleep(50)
pg.moveTo(856, 513)
pg.click()
pw = 'where the password is put'
time.sleep(1.5)
pg.typewrite(pw)
pg.press('enter')
time.sleep(10)
locator_1 = pg.locateCenterOnScreen('sidebarchaticon.png', confidence=0.9)
time.sleep(3)
pg.click(locator_1)
locator_2 = pg.locateCenterOnScreen('search.png', confidence=0.9)
time.sleep(3)
pg.click(locator_2)
time.sleep(0.5)
try:
locator_0 = pg.locateCenterOnScreen('encv.png', confidence=0.9)
time.sleep(3)
pg.click(locator_0)
except:
pass
time.sleep(0.5)
name_of_the_chat = 'specific chat room'
pg.typewrite(name_of_the_chat)
time.sleep(0.7)
locator_3 = pg.locateCenterOnScreen('chatroomicon.png', confidence=0.9)
time.sleep(3)
pg.doubleClick(locator_3)
time.sleep(1.5)
locator_4 = pg.locateCenterOnScreen('inside.png', confidence=0.9)
time.sleep(3)
pg.click(locator_4)
time.sleep(0.6)
pyperclip.copy('오늘은 ' + month + "월 " + day + "일 " + day_of_theweek + nl + \
'message 1' + nl + 'message 2(link)')
time.sleep(0.5)
pg.hotkey("ctrl", "v")
time.sleep(0.6)
pg.press('enter')
time.sleep(0.7)
pg.keyDown('altleft')
pg.press('f4')
pg.press('f4')
pg.keyUp('altleft')
decider = False
os.system('shutdown -s')
return schedule.CancelJob
schedule.every().monday.at("06:30").do(auto_daily_check)
schedule.every().tuesday.at("06:30").do(auto_daily_check)
schedule.every().wednesday.at("06:30").do(auto_daily_check)
schedule.every().thursday.at("06:30").do(auto_daily_check)
schedule.every().friday.at("06:30").do(auto_daily_check)
while decider:
schedule.run_pending()
time.sleep(1)