This is a read-only snapshot of the ComputerCraft forums, taken in April 2020.
schrolock's profile picture

disable ctrl+T

Started by schrolock, 20 July 2012 - 06:54 PM
schrolock #1
Posted 20 July 2012 - 08:54 PM
is it available to disable the ctrl+T function to avoid that my programs getting hacked?
MysticT #2
Posted 20 July 2012 - 08:57 PM
Hmmm, i don't know. Maybe one of all the posts in the forum about this has an answer.
Seriously, try searching first. There's a lot of posts about this, it's even on the wiki.
schrolock #3
Posted 20 July 2012 - 09:02 PM
ok thx
JATO457 #4
Posted 21 July 2012 - 09:21 AM
Place this at the top of your code:

os.pullEvent = os.pullEventRaw
schrolock #5
Posted 21 July 2012 - 05:37 PM
Place this at the top of your code:

os.pullEvent = os.pullEventRaw

Thank You
DireEpidemic #6
Posted 25 July 2012 - 11:55 AM
Awesome but cant they just restart it also?
Xfel #7
Posted 25 July 2012 - 05:31 PM
Yes, that can't be stopped. but with a suitable startup file, you can make your program show up on reboot again…
tfoote #8
Posted 25 July 2012 - 05:48 PM
question, is there a way to detect if they are pushing ctrl + t and stop it before it happens? if so that would be very helpfull… in my code I have an option for the program to autostart where it left off… if i could detect that before it happens i could tell it to automatically start where it left off…
Xfel #9
Posted 25 July 2012 - 06:16 PM
ctrl+t will post a "terminate"-event which can be received like any other event. However, os.pullEvent() catches that one and terminates the program. os.pullEventRaw() doesn't. you have to be careful as os.pullEvent() is also used in sleep() or rednet.recieve().
tfoote #10
Posted 26 July 2012 - 06:35 AM
ok. how much time is between the recieving of the event and the termination? can you change that time?
KingMachine #11
Posted 26 July 2012 - 07:01 AM
ok. how much time is between the recieving of the event and the termination? can you change that time?
It varies between processors of the hosting computer (ie the one that runs minecraft). To change that time would definitely include changing the rom.
Luanub #12
Posted 26 July 2012 - 10:11 AM
To catch the terminate event is very simple, however it will over ride the global os.pullEvent() so you will need to restore it when closing your program to regain ctrl+t functionality.

Add this to the top of your code:

function os.pullEvent()
    local event, p1, p2, p3, p4, p5 = os.pullEventRaw()
    if event == "terminate" then
   	 print ("Sorry Ctrl+t is disabled")
        sleep(2)
    end
    return event, p1, p2, p3, p4, p5
end

And use this function to restore the original

function restoreEvent()
    function os.pullEvent( _sFilter )
    local event, p1, p2, p3, p4, p5 = os.pullEventRaw( _sFilter )
    if event == "terminate" then
        print( "Terminated" )
        error()
    end
    return event, p1, p2, p3, p4, p5
end
end