Solved

Using KF_REPEAT

Posted on 2001-07-18
13
902 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
Creating Instructional Tutorials  

For Any Use & On Any Platform

Contextual Guidance at the moment of need helps your employees/users adopt software o& achieve even the most complex tasks instantly. Boost knowledge retention, software adoption & employee engagement with easy solution.

 

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

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!

Question has a verified solution.

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

When designing a form there are several BorderStyles to choose from, all of which can be classified as either 'Fixed' or 'Sizable' and I'd guess that 'Fixed Single' or one of the other fixed types is the most popular choice. I assume it's the most p…
Background What I'm presenting in this article is the result of 2 conditions in my work area: We have a SQL Server production environment but no development or test environment; andWe have an MS Access front end using tables in SQL Server but we a…
Get people started with the process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…
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…
Suggested Courses
Course of the Month5 days, 7 hours left to enroll

627 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