Solved

hack the VK_LEFT or VK_Right keys

Posted on 2001-07-05
11
353 Views
Last Modified: 2010-04-06
I have a component derived from TCustomControl . When I press left or right or up&down key the focus go to the next control .
But I wish to have this just for up or down keys .
How can I use left and right keys into my component to do something else?
0
Comment
Question by:ginsonic
11 Comments
 
LVL 27

Expert Comment

by:kretzschmar
ID: 6255220
you should catch the wm_keydown message

you could override the WMKEYDOWN-Method

do your stuff if the key is your one of your needed keys and set the key to null before doing an inherited call,
all other let process inherited

other possibilities may available

meikl ;-)
0
 
LVL 13

Expert Comment

by:Epsylon
ID: 6255355
Is there a reason you derived it from TCustomControl instead of TWinControl? If not then try TWinControl.
0
 

Expert Comment

by:felonious
ID: 6258377
like kretzschmar said, you could use the windows message for keydown, or just use the OnKeyDown event for the Control.  play around with this a bit..:

in an OnKeyDown event try:

case Key of
VK_Left : begin
            DoSomethingHere;
            Key := nil;
          end;
VK_Right: begin
            DoSomethingElseHere;
            Key := nil;
          end;
end;

setting key to nil after your code will insure that thats all that is executed for those key presses.  let me know if this helps.


felonious
0
 

Expert Comment

by:felonious
ID: 6258381
like kretzschmar said, you could use the windows message for keydown, or just use the OnKeyDown event for the Control.  play around with this a bit..:

in an OnKeyDown event try:

case Key of
VK_Left : begin
            DoSomethingHere;
            Key := nil;
          end;
VK_Right: begin
            DoSomethingElseHere;
            Key := nil;
          end;
end;

setting key to nil after your code will insure that thats all that is executed for those key presses.  let me know if this helps.


felonious
0
 

Expert Comment

by:felonious
ID: 6258383
oops
0
What Security Threats Are You Missing?

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

 
LVL 9

Author Comment

by:ginsonic
ID: 6262472
I have used this ... don't work .

procedure TMy.WMKeyDown(var Message: TWMKeyDown);
begin
  if Message.CharCode = VK_LEFT then
  Message.CharCode := null;
  inherited;
end;

But guys ... WMKeyDown and TCustomControl ?
0
 

Expert Comment

by:felonious
ID: 6263394
how bout changing the above code to:

begin
  if message.CharCode <> VK_LEFT then inherited;
end;
0
 

Expert Comment

by:felonious
ID: 6263400
hmm, you might also consider setting Message.Result = 0 (tells windows the message has been processed)

so, basicly, try your above code just adding Message.Result := 0;  if that doesn't work try


begin
 if message.CharCode <> VK_LEFT then inherited
 else
 begin
  message.CharCode := null;
  message.Result := 0;
 end;
end;


felonious
0
 
LVL 9

Author Comment

by:ginsonic
ID: 6655627
I forgot to check this questions . Sorry .. anothers jobs .
I will give an answer soon .
0
 
LVL 9

Author Comment

by:ginsonic
ID: 6674192
Not a comment work . I will delete this question , but already put a new one , with same content and with 200 point reward .
Thanks for suport ... and if you have new ideas then go to new request .
0
 
LVL 5

Accepted Solution

by:
Netminder earned 0 total points
ID: 6832367
Per user request, points refunded and question closed.

Netminder
Community Support Moderator
Experts Exchange
0

Featured Post

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

Objective: - This article will help user in how to convert their numeric value become words. How to use 1. You can copy this code in your Unit as function 2. than you can perform your function by type this code The Code   (CODE) The Im…
Hello everybody This Article will show you how to validate number with TEdit control, What's the TEdit control? TEdit is a standard Windows edit control on a form, it allows to user to write, read and copy/paste single line of text. Usua…
Internet Business Fax to Email Made Easy - With eFax Corporate (http://www.enterprise.efax.com), you'll receive a dedicated online fax number, which is used the same way as a typical analog fax number. You'll receive secure faxes in your email, fr…
When you create an app prototype with Adobe XD, you can insert system screens -- sharing or Control Center, for example -- with just a few clicks. This video shows you how. You can take the full course on Experts Exchange at http://bit.ly/XDcourse.

759 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

17 Experts available now in Live!

Get 1:1 Help Now