模拟鼠标移动的脚本保持唤醒。
import win.ui;
/*DSG{{*/
mainForm = win.form(text="禁止休眠";right=279;bottom=167)
mainForm.add(
button={cls="button";text="激活";left=32;top=104;right=112;bottom=136;z=2};
button4={cls="button";text="取消";left=160;top=104;right=240;bottom=136;z=3};
static={cls="static";text='\uF023 禁止休眠';left=32;top=32;right=128;bottom=56;font=LOGFONT(h=-16;name='FontAwesome');notify=1;transparent=1;z=1}
)
/*}}*/
import fonts.fontAwesome;
import mouse;
var moveMouse = function(){
// 最小设为1px
var stepPixel = 100;
mouse.move(stepPixel, 0);
mouse.move(0, stepPixel);
mouse.move(0 - stepPixel, 0);
mouse.move(0, 0 - stepPixel);
}
// 激活
mainForm.button.oncommand = function(id,event){
mainForm.intervalId = mainForm.setInterval(1000, moveMouse);
mainForm.button.disabled = true;
mainForm.button4.disabled = false;
}
// 取消
mainForm.button4.oncommand = function(id,event){
if(not mainForm.intervalId) {
return;
}
mainForm.clearInterval(mainForm.intervalId);
mainForm.intervalId = nil;
mainForm.button4.disabled = true;
mainForm.button.disabled = false;
}
// 退出时关闭
mainForm.onClose = function(hwnd,message,wParam,lParam){
if(mainForm.intervalId) {
mainForm.clearInterval(mainForm.intervalId);
mainForm.intervalId = nil;
}
}
mainForm.button4.disabled = true;
mainForm.show();
return win.loopMessage();