Jump to content




[Question] "isKeyDown"?


  • You cannot reply to this topic
4 replies to this topic

#1 Mmmmmmmm

  • Validating
  • 35 posts
  • LocationNorway

Posted 27 July 2012 - 10:16 PM

Would it be possible to do something like this?
local function isKeyDown(key)
  -- Check if key is being pressed
end
I don't mean something like os.pullEvent(), which would detect if the key is pressed once, but rather something that would detect if the key is being pressed.

#2 brett122798

  • Members
  • 300 posts
  • LocationIn the TARDIS at an unknown place in time.

Posted 28 July 2012 - 12:06 AM

local function isKeyDown(keynumber)
local e,key = os.pullEventRaw("key")
if key == keynumber then
<Execute Code>
end
end
Not tested, but I think it might work.

#3 ComputerCraftFan11

  • Members
  • 771 posts
  • LocationHawaii

Posted 28 July 2012 - 12:10 AM

Try this, I didn't test it yet:
local function isKeyDown(keyinput)
local timer112 = os.startTimer(0)
event, key = os.pullEvent()
if event == timer and key == timer112 then
  return false
elseif event == "char" or event == "key" then
  if keyinput == key then
   return true
  else
   return false
  end
else
  return false
end
end


#4 Xtansia

  • Members
  • 492 posts
  • LocationNew Zealand

Posted 28 July 2012 - 12:23 AM

View Postbrett122798, on 28 July 2012 - 12:06 AM, said:

local function isKeyDown(keynumber)
local e,key = os.pullEventRaw("key")
if key == keynumber then
<Execute Code>
end
end
Not tested, but I think it might work.

View PostComputerCraftFan11, on 28 July 2012 - 12:10 AM, said:

Try this, I didn't test it yet:
local function isKeyDown(keyinput)
local timer112 = os.startTimer(0)
event, key = os.pullEvent()
if event == timer and key == timer112 then
  return false
elseif event == "char" or event == "key" then
  if keyinput == key then
   return true
  else
   return false
  end
else
  return false
end
end

Both of those don't do what the person wants.

@EternalFacepalm Currently no, CC is very event driven with no static checking like that.

#5 Cloudy

    Ex-Developer

  • Members
  • 2,543 posts

Posted 28 July 2012 - 10:09 AM

As more than one person can use a computer at any one time this would not be trivial to add. However I'll try and think of a solution for the next version.





1 user(s) are reading this topic

0 members, 1 guests, 0 anonymous users