Go Premium for a chance to win a PS4. Enter to Win

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 929
  • Last Modified:

Using KF_REPEAT

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
jettrooper
Asked:
jettrooper
  • 6
  • 6
1 Solution
 
AZWolf7Commented:
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
 
jettrooperAuthor Commented:
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
 
KDivadCommented:
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
VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

 
jettrooperAuthor Commented:
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
 
KDivadCommented:
<<... to pull the bit out of the lParam ...>>

That's easy enough. Which bits do you need?
0
 
jettrooperAuthor Commented:
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
 
KDivadCommented:
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
 
KDivadCommented:
This should do it:

KeyRepeat = (lParam And (Not &HFFFF8001)) \ 2
0
 
jettrooperAuthor Commented:
I'll give it a try That does looks right.
0
 
KDivadCommented:
Never mind. I didn't read that right. It's bits 0 to 15. Change that to this:

KeyRepeat = lParam And (Not &HFFFF0000)
0
 
jettrooperAuthor Commented:
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
 
KDivadCommented:
I'm a bit confused (as usual). Where did my code help you?
0
 
jettrooperAuthor Commented:
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

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

  • 6
  • 6
Tackle projects and never again get stuck behind a technical roadblock.
Join Now