Computing.Net > Forums > Programming > vb6 count typed keys

Computer Problems? Computing.Net has over 1,000,000 posts about all things technology related! Over 90% answered within 24 hours! Click here to start participating now! Also, be sure to check out the New User Guide.

vb6 count typed keys

Reply to Message Icon

Name: MTec007
Date: April 21, 2008 at 13:59:30 Pacific
OS: XP Home 2002 SP2
CPU/Ram: Celeron 1.10GHz, 128
Product: HP Pavilion 510w
Comment:

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



Sponsored Link
Ads by Google

Response Number 1
Name: Razor2.3
Date: April 28, 2008 at 01:36:51 Pacific
Reply:

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.


0
Reply to Message Icon

Related Posts

See More







Post Locked

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


Go to Programming Forum Home


Sponsored links

Ads by Google


Results for: vb6 count typed keys

VB6 - File Type:ASCII or Binary www.computing.net/answers/programming/vb6-file-typeascii-or-binary/7112.html

how to disabled RUN key www.computing.net/answers/programming/how-to-disabled-run-key/556.html

encrypt and decrypt query string www.computing.net/answers/programming/encrypt-and-decrypt-query-string/15417.html