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

How to detect a user input while detecting an event l

Started by laica10, 20 April 2015 - 06:44 PM
laica10 #1
Posted 20 April 2015 - 08:44 PM
Hey i was writing an OS and i wanted to detect an user input (the password)
and in the meanwhile i wanted to detect for an Event ("mouse_click")

so maybe you guys could help me …
Lupus590 #2
Posted 20 April 2015 - 10:21 PM
you will want an event loop


while true do
  e, info[1],info[2],info[3] = os.pullEven()
  if e == "mouse_click" then
	mouseClickFunc(info)
  elseif e== "char" then --#this event name may be wrong
	inputfunc(info)
  end
end
if you want to use read then you will need to use the parallel API
Edited on 20 April 2015 - 08:23 PM
Creator #3
Posted 20 April 2015 - 10:29 PM
you will want an event loop


while true do
  e, info[1],info[2],info[3] = os.pullEven()
  if e == "mouse_click" then
	mouseClickFunc(info)
  elseif e== "char" or e == "key" then --#this event name may be wrong
	inputfunc(info)
  end
end
if you want to use read then you will need to use the parallel API

I adder or e == "key" since it is also used by read. What you could do is take the read function from the bios.lua and doing this:


while true do
  event = {os.pullEven()}
  if event[1] == "mouse_click" then
	mouseClickFunc(info)
  else
   put the internal part of the read function, that is to say everything inside while true do loop
  end
end
Edited on 20 April 2015 - 08:29 PM
laica10 #4
Posted 21 April 2015 - 03:41 PM
This works great but i actually wanna determine where they need to click, because now you could click everywhere and it would work,i would also like to determine a certain string for the input

No need for that anymore i found out already