View unanswered posts | View active topics It is currently May 22nd, '13, 12:29




Reply to topic  [ 3 posts ] 
 input.KeyGetState 
Author Message

Joined: Oct 18th, '09, 03:27
Posts: 82
Post input.KeyGetState
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 :eh:

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


Last edited by deadlyp99 on Nov 22nd, '09, 05:46, edited 1 time in total.

more information



Nov 22nd, '09, 05:37
Profile
Site Moderator
User avatar

Joined: Aug 18th, '09, 03:32
Posts: 1201
Post Re: input.KeyGetState
Ya, I actually told you about it in another post, but it probably didn't make sense at the time.

It's fixed in MM 2.01, but I was holding off on uploading it waiting for another problems.
I'll upload 2.01 tonight.

Also, do you want or need hot keys?
I was thinking of adding the windows hotkey API where you register a key, and MM will pick it up.
At the time, I could see how it would work, but I'm sure now it could just be polled.
You register each hot key you want to be notified about and any presses will show up as an
event.
A lot more reliable and smoother then polling key states.


Nov 22nd, '09, 20:27
Profile

Joined: Oct 18th, '09, 03:27
Posts: 82
Post Re: input.KeyGetState
It's very likely I didn't fully understand what you had said before. I knew from reading the api that the "2" state was unpredictable, but it seemed to easiest to predict ;]

Glad to hear that is fixed, though no particular rush on the new version. Take your time :thumbup:

I would love hotkeys, and I think others would too.
It would take something that will eventually be stickied code on the forum, and make it a built in function people can use.

I prefer gameplay in full screen mode, so unless I'm completely exiting my program I prefer to not need to tab out ;]


Nov 23rd, '09, 04:07
Profile
Display posts from previous:  Sort by  
Reply to topic   [ 3 posts ] 

Who is online

Users browsing this forum: No registered users and 0 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group.
Based on design by STSoftware, modded by Sirmabus Copyright© 2009-2011