52 posts
Posted 08 June 2013 - 12:50 AM
I was wondering how do I terminate a read() instead of entering key and pressing enter. I am making a window and it has a parallel.waitForAny() and when I load a different menu with a mouse click the read() is still there and when I type a key it printed the key on there and the background is setup differently.
295 posts
Location
In the TARDIS at an unknown place in time.
Posted 08 June 2013 - 02:21 AM
So are you wanting to input a single character and not press enter? That can be done like so:
while true do -- This loop will continue to listen for keys until it is broken.
event, key = os.pullEvent("key")
if key == 17 then -- If you press "w"
-- Stuffz
break
end
end
Here are the key codes for Minecraft so you can find out what code you need for the key you want to detect pressed:
http://www.minecraft.../wiki/Key_codes
52 posts
Posted 08 June 2013 - 02:52 AM
So are you wanting to input a single character and not press enter? That can be done like so:
while true do -- This loop will continue to listen for keys until it is broken.
event, key = os.pullEvent("key")
if key == 17 then -- If you press "w"
-- Stuffz
break
end
end
Here are the key codes for Minecraft so you can find out what code you need for the key you want to detect pressed:
http://www.minecraft.../wiki/Key_codes
I do know about os.pullEvent("key") and I know how to use it but I was thinking is there away just to terminate the read()?
So are you wanting to input a single character and not press enter? That can be done like so:
while true do -- This loop will continue to listen for keys until it is broken.
event, key = os.pullEvent("key")
if key == 17 then -- If you press "w"
-- Stuffz
break
end
end
Here are the key codes for Minecraft so you can find out what code you need for the key you want to detect pressed:
http://www.minecraft.../wiki/Key_codes
I do know about os.pullEvent("key") and I know how to use it but I was thinking, is there away just to terminate the read()?
295 posts
Location
In the TARDIS at an unknown place in time.
Posted 08 June 2013 - 03:28 AM
So are you wanting to input a single character and not press enter? That can be done like so:
while true do -- This loop will continue to listen for keys until it is broken.
event, key = os.pullEvent("key")
if key == 17 then -- If you press "w"
-- Stuffz
break
end
end
Here are the key codes for Minecraft so you can find out what code you need for the key you want to detect pressed:
http://www.minecraft.../wiki/Key_codes
I do know about os.pullEvent("key") and I know how to use it but I was thinking is there away just to terminate the read()?
Whew, I've never really thought about it.. give me some time. But could you also explain exactly what you are doing? I don't quite understand.
EDIT: I don't think it is possible to terminate the read function without multi-tasking. This is way more complex of an issue than you'd think.
60 posts
Posted 08 June 2013 - 04:43 AM
Simple, os.queueEvent("key", 28), that will simulate pressing enter. However this is almost like using error() to quit your program, You should never need to use either of these if you sort out your logic. Overall, It's possible but I don't recommend it.
7083 posts
Location
Tasmania (AU)
Posted 08 June 2013 - 05:27 AM
This code sample lets users type, while continuing on with the loop if they don't press a key within a certain amount of time. Pressing "q", for example, breaks out of the loop and ends the program.
You would basically adapt it to append each key pressed to a string (removing the last character if backspace were pressed), then have it break the loop when enter was pressed. You could also have it wait for other events and queue those when you want it to break out and stop.
http://www.computercraft.info/forums2/index.php?/topic/13315-moving-npc-problem/page__view__findpost__p__124214