Posted 15 March 2014 - 09:16 PM
Hello everyone. Im new to this forum (as a member, I've been reading it for a looooooooong time). My project needs an input method and I've chosen using the keyboard, but I want to get if a key is pressed or not. The problem is that in other input APIs you can choose between event driven input or "direct" inputs, but in CC i have to stay with events. When an event is called the routine waits for it, and stops everything (in that coroutine) but i need to wrap it around and get the "direct" keys, like looking for in a table where I have all the keys and a boolean telling if it's being pressed or not. In my mind, everything was perfect and worked as i wanted to, but in code, that's not the truth. Here's my code:
And I call the function with the Parallel API:
The problem is, when I display my table in a computer, all the values are 'false'. Is there a CC "vanilla" way to solve my problem or do I need a custom Java API?
[...]
function updateInput()
while RUNNING do
for i = 0, 0xF, 1 do
inputKeys[i] = false
end
local e, rawKey = os.pullEvent("key")
if rawKey == 82 then inputKeys[0x0] = true else inputKeys[0x0] = false end
if rawKey == 79 then inputKeys[0x1] = true else inputKeys[0x1] = false end
if rawKey == 80 then inputKeys[0x2] = true else inputKeys[0x2] = false end
if rawKey == 81 then inputKeys[0x3] = true else inputKeys[0x3] = false end
if rawKey == 75 then inputKeys[0x4] = true else inputKeys[0x4] = false end
if rawKey == 76 then inputKeys[0x5] = true else inputKeys[0x5] = false end
if rawKey == 77 then inputKeys[0x6] = true else inputKeys[0x6] = false end
if rawKey == 71 then inputKeys[0x7] = true else inputKeys[0x7] = false end
if rawKey == 72 then inputKeys[0x8] = true else inputKeys[0x8] = false end
if rawKey == 73 then inputKeys[0x9] = true else inputKeys[0x9] = false end
if rawKey == 210 then inputKeys[0xA] = true else inputKeys[0xA] = false end
if rawKey == 199 then inputKeys[0xB] = true else inputKeys[0xB] = false end
if rawKey == 201 then inputKeys[0xC] = true else inputKeys[0xC] = false end
if rawKey == 211 then inputKeys[0xD] = true else inputKeys[0xD] = false end
if rawKey == 207 then inputKeys[0xE] = true else inputKeys[0xE] = false end
if rawKey == 209 then inputKeys[0xF] = true else inputKeys[0xF] = false end
end
end
[...]
inputKeys is a table, where I store the state of each key.And I call the function with the Parallel API:
parallel.waitForAny(main, updateInput)
main() is only the main loop, nothing special there.The problem is, when I display my table in a computer, all the values are 'false'. Is there a CC "vanilla" way to solve my problem or do I need a custom Java API?