Sign in to follow this  
jagguy2

static variables

Recommended Posts

I am trying to get the number of milliseconds i hold down a key The reason being is that if i hold it down for more than 1 sec I will do fire another missile (game play). The problem is that all i get is 31 MS for just a press of the key or a slightly longer press? Basically i am not doing getting the timespan of the keypress. this procure gets called until i let go of the ctrl button where it will remove the key from a list. Dim startt As DateTime = Now Dim endt As DateTime = Now Static mytime As TimeSpan = endt.Subtract(startt) If dict.ContainsKey(Key.Ctrl) Then endt = Now mytime = mytime + endt.Subtract(startt) txt1.Text = txt1.Text & mytime.Milliseconds.ToString For i = 0 To 19 If missile(i).fire = False Then missile(i).y = 0 missile(i).fire = True txt1.Text = txt1.Text & " fire1 " ' mytime = Now.Subtract(Now) ' dict.Remove(Key.Ctrl) Exit For End If Next End If 'this does work Private Sub getKeyUp(ByVal sender As System.Object, ByVal e As System.Windows.Input.KeyEventArgs) dict.Remove(e.Key) End Sub

Share this post


Link to post
Share on other sites
If you remove the item from the dict when the key is released, then you should be expecting the dict not to contain the item when you check for a key-release, no?

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this