new version:
added a text field to input time. it will store the input in a text file. you can input the time in seconds, minutes, hours, days, weeks and years. just write 1m for 1 minute, 1h for 1 hour and so on. 10 years is the maximum.
i added some checks, but you are responsible to not make any weird entries.
copy, cut and paste is possible with ctrl+c,v,x
set display mode 220,96,32
set window title "ShutIt"
time$=""
if file exist("conf.txt")=1
open to read 1,"conf.txt"
read string 1,time$
endif
sync on
sync rate 30
sync sleep 1
sync
ink 0xffffffff
drawBoxOutline(10,10,210,27)
drawBoxOutline(10,30,210,47)
drawBoxOutline(10,50,210,67)
drawBoxOutline(10,70,210,87)
blur bitmap 0,3
ink 0xffb0b0b0
drawBoxOutline(10,10,210,27)
drawBoxOutline(10,30,210,47)
drawBoxOutline(10,50,210,67)
drawBoxOutline(10,70,210,87)
ink 0xffffffff
text 20,11,time$
text 20,31,"start shutdown timer"
text 20,51,"cancel shutdown"
text 20,71,"close"
sync
editText=0
disable escapekey
do
mLclick=getMouseClick(1,mLclick)
if mLclick=3
if mouseInside(10,10,210,27)
clear entry buffer
editText=1
endif
if mouseInside(10,30,210,47)
seconds$=getTimeString(time$)
if seconds$<>"" then run("shutdown /s /t "+seconds$)
endif
if mouseInside(10,50,210,67) then run("shutdown /a")
if mouseInside(10,70,210,87) or escapekey()
if file exist("conf.txt")=1 then delete file "conf.txt"
open to write 1,"conf.txt"
write string 1,time$
close file 1
exit
endif
endif
if editText=1
time$=getInput(time$,22)
box 20,12,196,26,0xffa5a5a5
text 20,11,time$
sync
if returnkey()=1 or (mLclick=3 and mouseInside(10,10,210,27)=0)
box 20,12,196,26,0xff000000
text 20,11,time$
sync
editText=0
endif
endif
loop
end
function getTimeString(s$)
unit$=lower$(right$(s$,1))
value=val(s$)
select unit$
case "m":
//minutes
value=value*60
endcase
case "h":
//hours
value=value*60*60
endcase
case "d":
//days
value=value*60*60*24
endcase
case "w":
//weeks
value=value*60*60*24*7
endcase
case "y":
//years
value=value*60*60*24*365
if value=315360000 then value=315359999
endcase
endselect
if value>=315360000 or value=0 then s$="" else s$=str$(value)
endfunction s$
function run(command$)
ret=execute executable ("cmd","/C "+command$,"")
endfunction
function mouseInside(x1,y1,x2,y2)
ret=mousex()>x1 and mousex()<x2 and mousey()>y1 and mousey()<y2
endfunction ret
function getMouseClick(btn,oldState)
state=(mouseClick() and btn) / btn
newState=oldState
select oldState
case 0:
if state=1 then newState=2
endcase
case 1:
if state=0 then newState=3
endcase
case default:
newState=state
endcase
endselect
ENDFUNCTION newState
function drawBoxOutline(x1,y1,x2,y2)
line x1,y1,x2,y1
line x2,y1,x2,y2
line x2,y2,x1,y2
line x1,y1,x1,y2
endfunction
function getInput(oldString$,length)
add$=entry$()
clear entry buffer
for i=1 to len(add$)
char$=mid$(add$,i)
oldString$=handleCharacter(oldString$,char$,length)
NEXT i
endfunction oldString$
function handleCharacter(oldString$,char$,length)
ascii=asc(char$)
select ascii
case 8
oldString$ = left$(oldString$,len(oldString$)-1)
endcase
case default
if len(oldString$)<length
if (ascii>47 and ascii<58) and asc(lower$(right$(oldString$,1)))<58
oldString$=oldString$+char$
ENDIF
if ascii>64 and ascii<123 and asc(lower$(right$(oldString$,1)))<58
ascii=asc(lower$(char$))
if ascii=115 or ascii=109 or ascii=104 or ascii=100 or ascii=119 or ascii=121
oldString$=oldString$+char$
endif
endif
endif
if ascii = 22 then oldString$=oldString$+left$(get clipboard$(),length-len(oldString$))
if ascii = 3 then write to clipboard oldString$
if ascii = 24 then write to clipboard oldString$ : oldString$=""
endcase
endselect
endfunction oldString$
now it makes a bit more sense but the code is a bit bloated
"It is only slightly easier than changing all sugar in a cake into stevia after it has already been baked" -Bisqwit