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

Question about os.pullEvent("char")

Started by ElmuKelmuZ, 27 June 2014 - 02:45 AM
ElmuKelmuZ #1
Posted 27 June 2014 - 04:45 AM
For some reason, even if I press the "5"-key, the computer does not shut down like it should.
What am I doing wrong here?



local cafos = {
dialogs = {
mainuserwindow = {
"CafOS",
"2014 (c) Caffeine Spider Ltd",
"Logged in as blablalb",
"",
"1. Transmit wireless signal",
"2. Shut down mainframe",
"3. Information",
"4. Log out",
"5. Shut down",
"6. Boot from Disk",
"7. More"
},
}}

function createDialog(opts, getInput, password, textInput)
clear()
for k,v in pairs(opts) do
write(v.."\n")
end
if getInput then
if textInput then
if password then
local inp = read("*")
return inp
else
local inp = read()
return inp
end
else
local event, key = os.pullEvent("char")
return keys.getName(key)
end
end
return true
end

function clear(noCursor)
term.clear()
if noCursor == nil then
term.setCursorPos(1,1)
end
end

function update()
clear()

local menuSelection = createDialog(cafos.dialogs.mainuserwindow, true, false, false)

if menuSelection == "one" then
--asdasddsds
elseif menuSelection == "two" then
--asdasddsds
elseif menuSelection == "three" then
--asdasddsds
elseif menuSelection == "four" then
--asdasddsds
elseif menuSelection == "five" then
print("")
print("Shutting down..")
sleep(1)
os.shutdown()
elseif menuSelection == "six" thenend
return true
end

while true do
local runtime = update()
if runtime == false then
break
end
end

Edited on 27 June 2014 - 02:48 AM
Anavrins #2
Posted 27 June 2014 - 06:10 AM
If you press 5, the char event return {"char", 5}
keys.getNames(5) actually returns "four"
keys.getNames() is used to convert a key ID into it's "char" counterpart.
You pretty much need to change the os.pullEvent to listen to the "key" event instead.
ElmuKelmuZ #3
Posted 27 June 2014 - 07:27 AM
If you press 5, the char event return {"char", 5}
keys.getNames(5) actually returns "four"
keys.getNames() is used to convert a key ID into it's "char" counterpart.
You pretty much need to change the os.pullEvent to listen to the "key" event instead.

Thank you! You made this possible :3
http://pastebin.com/mgN2BK2c