How do i capture both key and a char event in the os.pullevent
#1
Posted 18 February 2013 - 04:23 PM
#2
Posted 19 February 2013 - 03:41 AM
#3
Posted 19 February 2013 - 03:51 AM
while true do
local event, param1 = os.pullEvent()
if event == "key" then
-- key was pressed
elseif event == "char" then
-- key with a char was pressed
end
end
#4
Posted 19 February 2013 - 04:58 PM
#5
Posted 19 February 2013 - 04:59 PM
#6
Posted 19 February 2013 - 05:00 PM
roosterhat, on 19 February 2013 - 04:58 PM, said:
function read() do local input = "" while true do local event, p = os.pullEvent() if event == "char" then input = input..p elseif event == "key" then if p == keys.enter then return input elseif p == keys.backspace then input = input:sub(1, #input - 1) end end end error( "should never get here" ) end
Edited by TheOriginalBIT, 19 February 2013 - 05:03 PM.
#7
Posted 19 February 2013 - 05:02 PM
Edited by TheOriginalBIT, 19 February 2013 - 05:03 PM.
#8
Posted 19 February 2013 - 05:07 PM
keys = {}
while true do
keys[1]=""
keys[2]=""
local event, param1 = os.pullEvent()
if event == "key" then
key[1] = param1
elseif event == "char" then
key[2] = param2
end
end
roosterhat, on 19 February 2013 - 05:06 PM, said:
keys = {}
while true do
keys[1]=""
keys[2]=""
local event, param1 = os.pullEvent()
if event == "key" then
key[1] = param1
elseif event == "char" then
key[2] = param2
end
end
#10
Posted 19 February 2013 - 05:14 PM
#11
Posted 19 February 2013 - 05:15 PM
#12
Posted 19 February 2013 - 05:15 PM
#13
Posted 19 February 2013 - 05:17 PM
roosterhat, on 19 February 2013 - 05:15 PM, said:
function read() do local input = "" local cx,cy = term.getCursorPos() while true do local event, p = os.pullEvent() if event == "char" then input = input..p elseif event == "key" then if p == keys.enter then return input elseif p == keys.backspace then input = input:sub(1, #input - 1) end end term.setCursorPos(cx,cy) write(input.." ") end error( "should never get here" ) endthen you use it just the same as normal read.
write("Your name: ")
local name = read()
could even add a password mask just like the real read. would call it like this:
write("Your pass: ")
local pass = read("*")
and in the read code you would do thisfunction read( mask ) -- .... other code here term.setCursorPos(cx,cy) write( ( mask and string.rep(mask, #input) or input ).." ") end
Edited by TheOriginalBIT, 19 February 2013 - 05:21 PM.
#14
Posted 19 February 2013 - 05:29 PM
#15
Posted 19 February 2013 - 05:30 PM
#16
Posted 19 February 2013 - 05:35 PM
missing the #
#17
Posted 19 February 2013 - 05:37 PM
2 user(s) are reading this topic
0 members, 2 guests, 0 anonymous users











