386 posts
Location
France
Posted 26 November 2012 - 03:33 AM
Hello all !
I ask you guys if there is a shutdown event when the ctrl+s are done ? It's because I do a program that do something important and I don't want the user to shutdown the computer. If this event doesn't exist, is there a way to block ctrl+s ?
Thanks you.
1114 posts
Location
UK
Posted 26 November 2012 - 03:48 AM
That would be useful
386 posts
Location
France
Posted 26 November 2012 - 03:59 AM
That would be useful
That's why I ask for it XD
1214 posts
Location
The Sammich Kingdom
Posted 26 November 2012 - 04:00 AM
You can just modify coroutine.
local oldCo = coroutine.yeild
coroutine.yeild() = nil
Not sure if it works though.
386 posts
Location
France
Posted 26 November 2012 - 04:09 AM
You can just modify coroutine.
local oldCo = coroutine.yeild
coroutine.yeild() = nil
Not sure if it works though.
So there is no event ? Because i don't understand what the coroutines are for so I don't want to touch it until I u'derstand it at least a bit…
1214 posts
Location
The Sammich Kingdom
Posted 26 November 2012 - 04:10 AM
You can just modify coroutine.
local oldCo = coroutine.yeild coroutine.yeild() = nil
Not sure if it works though.
So there is no event ? Because i don't understand what the coroutines are for so I don't want to touch it until I u'derstand it at least a bit…
Well os.pullEvent uses coroutine thus making coroutine nil will stop coroutine and stop shutting down and restarting.
386 posts
Location
France
Posted 26 November 2012 - 04:13 AM
You can just modify coroutine.
local oldCo = coroutine.yeild coroutine.yeild() = nil
Not sure if it works though.
So there is no event ? Because i don't understand what the coroutines are for so I don't want to touch it until I u'derstand it at least a bit…
Well os.pullEvent uses coroutine thus making coroutine nil will stop coroutine and stop shutting down and restarting.
Ok thanks you but after I do that os.pullEvent wille not work anymore ?
16 posts
Posted 26 November 2012 - 04:15 AM
However, if you do this, you
definitely want to back up coroutine.yield to some other variable, then restore it. Because without that, read() won't even work. You won't be able to run a single program.
e.g.
cobackup = coroutine.yield
coroutine.yield = nil
-- Your Code Here
coroutine.yield = cobackup
Also, these events are hardcoded, so I'm not sure if that really would work.
1214 posts
Location
The Sammich Kingdom
Posted 26 November 2012 - 04:16 AM
However, if you do this, you definitely want to back up coroutine.yield to some other variable, then restore it. Because without that, read() won't even work. You won't be able to run a single program. Also, these events are hardcoded, so I'm not sure if that really would work.
If you looked at the code I did back it up. This is the only way I know of to stop shutting down though.
386 posts
Location
France
Posted 26 November 2012 - 04:22 AM
Thanks you all alot ! I will try this and see :D/>/>
2005 posts
Posted 26 November 2012 - 07:11 AM
What good does the event do if the computer shuts down?
1688 posts
Location
'MURICA
Posted 26 November 2012 - 07:13 AM
What good does the event do if the computer shuts down?
One could have a program save data before the computer shuts down, maybe?
Then again, you could just have the program save said data and then shut the computer down, but it's always nice to have a fail safe when the user does it manually.
8543 posts
Posted 26 November 2012 - 08:06 AM
You can just modify coroutine.
local oldCo = coroutine.yeild
coroutine.yeild() = nil
Not sure if it works though.
Don't suggest things like this without knowing what the consequences would actually be. If you corrected that piece of code so that it actually did what you think it should, all you'd do is cause the computer to throw an attempt to call nil error. You would not get around the shutdown or restart keys in any way, shape or form.
2005 posts
Posted 26 November 2012 - 02:06 PM
I guess someone should have answered the question, now that I think of it. When the user first presses Ctrl+S or Ctrl+R, the key events for the Ctrl key and the S or R keys are received like normal. So you should be able to do something like just have the computer write itself a file mentioning that it's getting a shutdown command (and delete that file a few seconds later if it turned out to be a false alarm).
Or, you could have the computer activate a deadly trap that will kill the user for their temerity. But beware of the false positive.
386 posts
Location
France
Posted 27 November 2012 - 07:03 AM
I guess someone should have answered the question, now that I think of it. When the user first presses Ctrl+S or Ctrl+R, the key events for the Ctrl key and the S or R keys are received like normal. So you should be able to do something like just have the computer write itself a file mentioning that it's getting a shutdown command (and delete that file a few seconds later if it turned out to be a false alarm).
Or, you could have the computer activate a deadly trap that will kill the user for their temerity. But beware of the false positive.
Yeah that's what I thougt first but I searched an easyer way to do that. Thanks you all. :)/>