static variables

Started by
1 comment, last by jagguy2 15 years, 9 months ago
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
Advertisement
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?
no i dont need to test because it will automatically be deleted from the remove key event. I just need to reset the variable

This topic is closed to new replies.

Advertisement