-
Oct 27th, 2009, 03:28 PM
#1
Thread Starter
Member
GetAsyncKeyState errors?
Hi, I'm trying to make an app for another application using GetAsyncKeyState.
I coded what I thought to be good and clicked "Build". When I opened it, I tested it in notepad. When I hit NumPad2, it should return
or Instead, it returns:
Code:
`camera_control 0`camera_control 1`camera_control 0`camera_control 1`camera_control 0
or
Code:
`camera_control 1`camera_control 0`camera_control 1`camera_control 0`camera_control 1
This is my code:
Code:
Public Declare Function GetAsyncKeyState Lib "user32" (ByVal vKey As Long) As Integer
Public camcont As Boolean = False
Public curplayer As Integer = 0
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
End Sub
Private Sub Timer1_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer1.Tick
If Timer1.Enabled = True Then
Timer1.Interval = 1
If GetAsyncKeyState(Keys.NumPad2) Then
If camcont = False Then
SendKeys.Send("`")
SendKeys.Send("camera_control 1")
camcont = True
Else
SendKeys.Send("`")
SendKeys.Send("camera_control 0")
camcont = False
End If
End If
If GetAsyncKeyState(Keys.NumPad1) Then
If camcont = True Then
curplayer = curplayer + 1
SendKeys.Send("`")
SendKeys.Send("if (unit (list_get (players) " & curplayer & ")) (camera_set_first_person (unit (list_get (players) " & curplayer & ")))")
'SendKeys.Send("camera_set_first_person (unit (list_get (players) " & curplayer & "))")
End If
End If
If GetAsyncKeyState(Keys.NumPad3) Then
If camcont = True Then
curplayer = curplayer - 1
SendKeys.Send("`")
SendKeys.Send("if (unit (list_get (players) " & curplayer & ")) (camera_set_first_person (unit (list_get (players) " & curplayer & ")))")
'SendKeys.Send("camera_set_first_person (unit (list_get (players) " & curplayer & "))")
End If
End If
End If
End Sub
How would I make it return as it should?
I am using VS 2010 with .NET framework 4.0 Beta 1.
Thanks for any help,
-Arightwizard
The following statements are true. The following statement is false. The first statement is true.
-
Oct 27th, 2009, 03:35 PM
#2
Re: GetAsyncKeyState errors?
The function returns 1 if the key is still down after you have already checked it. Check instead against Integer.MaxVal to see if the key is down. It's returning these keys because you are holding down the key long enough for the Timer to detect more than one keypress.
-
Oct 27th, 2009, 03:50 PM
#3
Thread Starter
Member
Re: GetAsyncKeyState errors?
The following statements are true. The following statement is false. The first statement is true.
-
Oct 27th, 2009, 03:53 PM
#4
Re: GetAsyncKeyState errors?
Please mark threads Resolved if you have no more questions.
Tags for this Thread
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|