Solved

Using KF_REPEAT

Posted on 2001-07-18
13
895 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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
PeopleSoft Has Never Been Easier

PeopleSoft Adoption Made Smooth & Simple!

On-The-Job Training Is made Intuitive & Easy With WalkMe's On-Screen Guidance Tool.  Claim Your Free WalkMe Account Now

 

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
 
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

Enroll in May's Course of the Month

May’s Course of the Month is now available! Experts Exchange’s Premium Members and Team Accounts have access to a complimentary course each month as part of their membership—an extra way to increase training and boost professional development.

Question has a verified solution.

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

I’ve seen a number of people looking for examples of how to access web services from VB6.  I’ve been using a test harness I built in VB6 (using many resources I found online) that I use for small projects to work out how to communicate with web serv…
You can of course define an array to hold data that is of a particular type like an array of Strings to hold customer names or an array of Doubles to hold customer sales, but what do you do if you want to coordinate that data? This article describes…
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…
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…

734 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