Solved

Using KF_REPEAT

Posted on 2001-07-18
13
877 Views
Last Modified: 2010-08-05
Someone provide me with a good example of usinf the KF_REPEAT flag in a KeyDown method of a textbox.
I need to grab the message with either peekmessage or getmessage and evaluate the flags for repeated numbers so I can ignore them.
0
Comment
Question by:jettrooper
  • 6
  • 6
13 Comments
 

Expert Comment

by:AZWolf7
ID: 6295706
Why not just put something like this in the KeyPress event? In this very simple example, it will only allow one of any type of value. It could easily be converted to just handle numbers, etc. or the KeyDown event if you have to use that event.


If InStr(Text1.Text, Chr$(KeyAscii)) Then KeyAscii = 0


0
 

Author Comment

by:jettrooper
ID: 6295794
The problem is that I want to capture only the first KeyDown in the textbox. The code If InStr(Text1.Text, Chr$(KeyAscii)) Then KeyAscii = 0 won't work because I need to evaluate the Shift state and may have ALT + L where L will be detected where it shouldn't be. That is why I must use the API with getmessage.

0
 
LVL 5

Expert Comment

by:KDivad
ID: 6297046
Are you determined to use the KF_REPEAT method? I may be able to throw something together using GetAsyncKeyState. You can watch the keys a little better with it.

Basic idea:
Key Down 32768
Key Down Not Sending 32767
Key Up 0 or 1
If the key wasn't just 0 or 1, then ignore it. Otherwise, add the key to the textbox. Set array index to the current value.

It's fairly simple, but requires a loop or timer event and you have to loop through every KeyCode you are interested in...
0
 

Author Comment

by:jettrooper
ID: 6298510
The Problem with the GetAsyncKeyState is that I have to use the KeyDown Method because I need the ShiftState. and the KeyCode variable is not a true asci number that will always work with GetAsyncKeyState because GetAsyncKeyState uses the virtual keycodes which aren't alway te same.
I want to convert the C code that normally handles this into VB:
// repeat flag not set then increment
if ( ( HIWORD(lParam) & KF_REPEAT) == 0 )

The lParam variable holds both the WM_KEYDOWN message and the KF_REPEAT. If you know how to pull the bit out of the lParam in VB that should do it.
0
 
LVL 5

Expert Comment

by:KDivad
ID: 6299028
<<... to pull the bit out of the lParam ...>>

That's easy enough. Which bits do you need?
0
 

Author Comment

by:jettrooper
ID: 6299146
Here is the Microsoft article on the bits:
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/winui/hh/winui/keybinpt_7wvn.asp

So I need to pull the repeat key count.
0
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 
LVL 5

Expert Comment

by:KDivad
ID: 6299165
If I read that right, then bits 1 to 14 indicate the count. I don't think this is going to do quite what you want, but give me a couple minutes and I'll assemble the code to do it...
0
 
LVL 5

Expert Comment

by:KDivad
ID: 6299188
This should do it:

KeyRepeat = (lParam And (Not &HFFFF8001)) \ 2
0
 

Author Comment

by:jettrooper
ID: 6299189
I'll give it a try That does looks right.
0
 
LVL 5

Accepted Solution

by:
KDivad earned 100 total points
ID: 6299192
Never mind. I didn't read that right. It's bits 0 to 15. Change that to this:

KeyRepeat = lParam And (Not &HFFFF0000)
0
 

Author Comment

by:jettrooper
ID: 6299499
Hey That did it here is the final Code:

With m
    .hwnd = txtHotKey.hwnd
    .message = WM_KEYDOWN
    .lParam = KF_REPEAT
End With
ret = PeekMessage(m, vbNull, 0, 0, PM_NOREMOVE)
If (m.lParam And (KF_REPEAT)) Then Exit Sub

Thank for the assist
0
 
LVL 5

Expert Comment

by:KDivad
ID: 6299621
I'm a bit confused (as usual). Where did my code help you?
0
 

Author Comment

by:jettrooper
ID: 6299630
I couldn't remember howto do a bit comparison in VB. You really did help if not just helping me step through the problem Thanks alot
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Introduction While answering a recent question (http://www.experts-exchange.com/Q_27402310.html) in the VB classic zone, I wrote some VB code in the (Office) VBA environment, rather than fire up my older PC.  I didn't post completely correct code o…
If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…

896 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

19 Experts available now in Live!

Get 1:1 Help Now