Hello All.
I was Just Poking around and came across this thread, and while the code that started the thread was simple and rather useless, I got an Idea from it and decided to put together a small program using the base idea which was to create a virtual interface and show some kind of interaction between the user and the interface. after I built the screen locking part, I realized it would be perfect for a locking screen saver, so I built a simple random screen saver to run when the screen is locked, and it also makes the interface have a reason to lock and unlock the screen.
since I did this as a way to show the original author how to better utilize his original idea, I took a lot of time and Commented on almost all the code in the project so that other NewB's would be able to learn something as well. (I know I have learned alot from others who have done the same, so I am following suit.)
anyway here is the code I came up with so far. it's a great start and can be changed in lots of ways to make other programs as well. I have a bunch of ideas that came to mind while getting this far, but I will save them for another time\project.
I will be adding this to the code base as well.
rem **********************
rem Project Screen Locker
rem **********************
rem By Jon Ericson
rem **********************
rem Created 8-20-07
rem **********************
sync on : sync rate 10
hide mouse
sH=screen height()
sW=screen width()
set cursor sW /2-200,sH /2
set text font "arial"
set text to bold
set text size 28
`passCode = unlock <= this is so people know how to unlock it before building it.
` Here we will disable the the Escape Key, this is so people can't get out of the
` program by hitting the escape key. ( if this is intended for locking the screen.)
` ( I am leaving this commented out so you can escape, but you can enable it when building your app. just remove the ` mark)
`disable escapekey (<- moved to the locking sequence for better continuity.)
` sync commands will cause the screen to refresh, you may see them in different places.
sync
` now we get the input for the question "Activate Computer Lock?"
input "Activate Computer Lock y/n",yn$ `set input to a variable.
if yn$="n"
end ` if they say no then exit the program.
endif
`give a sense of something happening...
cls
cls
set cursor sW /2-200,sH /2
ink rgb(255,155,0),rgb(0,0,0)
print "Initiating Locking Sequence."
sync
wait 1000
set cursor sW /2-200,sH /2+20
ink rgb(255,204,50),rgb(0,0,0)
Print "Closing Outside Connections."
set cursor sW /2-200,sH /2+40
print "Closing Internal Connections."
sync
wait 1000
set cursor sW /2-200,sH /2+60
ink rgb(0,150,255),rgb(0,0,0)
print "All Connections Closed, Continuing Lock Down Sequence."
sync
wait 1000
set cursor sW /2-200,sH /2+80
ink rgb(255,255,255),rgb(0,0,0)
print "disabling keyboard keys"
sync
disable escapekey
wait 1000
set cursor sW /2-200,sH /2+100
ink rgb(10,255,0),rgb(0,0,0)
print "Done."
sync
wait 1000
`change the ink color to show there is now a difference
ink rgb(100,100,230),rgb(0,0,0)
`tell the user the screen is now locked and how to start the unlock sequence.
cls
set cursor sW /2-200,sH /2
print "Screen is Locked, Press P to enter Unlock Code"
sync
` start the main program loop
do
` put a screen saver code or whatever code you want here....
for a = 1 to 20
` for a normal 640x480 resolution
`text rnd(480),rnd(640),"screen is locked"
`for my machine which has high resolution, you could use a function to set this automaticaly.
text rnd(1680),rnd(1050),"Screen is Locked, Press P to enter Unlock Code"
`use this statement durring testing to make sure you can get out easy if something goes wrong,
`then rem it out for your build (to disable escape key.)
if scancode() = 1 then end
`wait for user to press the P button
if scancode() = 25
` if the user pressed the P button then start the unlock sequence.
`ask the user for the pre-set password.
cls
set cursor sW /2-200,sH /2
ink rgb(100,255,20),rgb(0,0,0)
print "Enter Password"
set cursor sW /2-200,sH /2+20
ink rgb(0,0,255),rgb(0,0,0)
input " ",Pass$
sync
if pass$="unlock"
` if the password is correct then we tell the user and then exit
`reset ink color for new message.
ink rgb(0,255,0),rgb(0,0,0)
cls
set cursor sW /2-200,sH /2
Print "Computer unlocked"
sync
` tell the screen to wait 2 seconds before exiting so the user can see the message.
wait 2000
`exit the program
end
endif
`recolor the ink to give this message
ink rgb(255,0,0),rgb(0,0,0)
` if the password was wrong then tell the user to try again
cls
set cursor sW /2-200,sH /2
Print "Password Incorrect, Please press P to try again."
` set ink color back again
ink rgb(200,100,100),rgb(0,0,0)
`reset for next attempt.
endif
sync
` wait for the user to make a move by pressing a key.
` finish screen saver code here.
` if a is = to 19 then reset it to 0 (we will add 1 to it in a second.)
if a => 19
cls
a = 0
`randomize the font color for the next loop
ink rgb(rnd(255),rnd(255),rnd(255)),rgb(0,0,0)
endif
` add 1 to "a" to increment (in case it's now zero from being reset.)
a=a+1
wait 100
` go back to begining of sequence and run through it again.
next a
`end the main loop
loop
`the end.
I know that I used the sync command alot but I was having trouble getting the text to appear on screen without it. if anyone knows of a way around this I would like to hear it. (Thanks!)
anyway like I said it's a simple thing but shows lots of promise I think. it requires no outside resources, and runs pretty smooth.
Have Fun!