Solved

Using KF_REPEAT

Posted on 2001-07-18
13
872 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
Maximize Your Threat Intelligence Reporting

Reporting is one of the most important and least talked about aspects of a world-class threat intelligence program. Here’s how to do it right.

 
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

6 Surprising Benefits of Threat Intelligence

All sorts of threat intelligence is available on the web. Intelligence you can learn from, and use to anticipate and prepare for future attacks.

Join & Write a Comment

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…
Most everyone who has done any programming in VB6 knows that you can do something in code like Debug.Print MyVar and that when the program runs from the IDE, the value of MyVar will be displayed in the Immediate Window. Less well known is Debug.Asse…
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…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…

760 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