While playing around, I noticed the input.KeyGetState function seems a little buggy.
While holding X, it will report the key as down for a few polls then reset to not being down.
If I slowly tap the key, the poll acts like a boolean. I'll press my key once, and it will show down for a while, and when I release the key there is not change. If I again tap it, it will report as not being down.
It seems like while reading keys of the keyboard it doesn't actually update the value of input.KeyGetState, but maybe instead checks if the key changed
To demonstrate I've put some source.
Perhaps I am trying to use this function incorrectly? My goal isn't to have it functioning as a boolean
Code:
function MainPoll()
GetKeyState("x")
end
function GetKeyState(sKey)
iKeyState = input.KeyGetState(sKey)
if sKey == "x" then
if iKeyState == 1 then
print "X is down"
else
print "X is NOT down"
end
end
end
while true do
MainPoll()
time.Sleep(0.075)
end
I actually found something interesting
I took a look at what the key state value is.
Code:
if iKeyState == 1 then
print("X is down "..iKeyState)
else
print("X is NOT down "..iKeyState)
end
Looks like when the key is held down long enough it changes he key state to 2, and when you release the key the key state goes back to 1, instead of 0 like it should. After that, if you press and hold the key again, it will go from 1 to 2, and when the key is released it will finally go to 0.
so
Code:
0
0
0
press and hold x
1
1
1
2
2
2
2
2
2
release x
1
1
1
1
1
1
1
press and hold x
2
2
2
2
2
2
2
2
release x
0
0
0
0