Tom's Guide | Tom's Hardware | Tom's Games
![]() |
![]() |
![]() |
I'm trying to figure out how to count the number of keystrokes that are typed and increment a variable +1.
For example, if I typed in "Hello World!",
my variable should equal 15 because of shift, and space. I'm pretty sure GetAsyncKeyState() in user32.dll is the way to go, but I can't make it function correctly. Some keys (ctrl, alt etc) will increment my variable +2 instead of +1, and if I hold a key in, the variable will increase until the key is let go, and I dont want that either. I'm trying to get keystrokes typed anywhere in the Win32 API not just my app.Private Declare Function GetAsyncKeyState Lib "user32" (ByVal vKey As Long) As Integer
Dim X, i, newCount As Integer
For i = 0 To 255
X = GetAsyncKeyState(i)
If X = -32767 Then
newCount = newCount + 1
End If
Next

Man, I'm gone for a week and no one posts an answer. What's up with that?
Some keys (ctrl, alt etc) will increment my variable +2 instead of +1
That's because Ctrl, Alt, and Shift are listed a few times: once for the right key, once for the left key, and once for either key.Also, 1-6 are mouse buttons, so you'll probably not want to catch that.
if I hold a key in, the variable will increase until the key is let go
You'll need to remember the previous values and compare them to your current results.

![]() |
![]() |
![]() |

This post is quite old and has been locked from receiving new replies. Please create a new posting instead.
| Ads by Google |