?
Solved

hack the VK_LEFT or VK_Right keys

Posted on 2001-07-05
11
Medium Priority
?
361 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
[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
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
Technology Partners: 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!

 

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

[Webinar] Lessons on Recovering from Petya

Skyport is working hard to help customers recover from recent attacks, like the Petya worm. This work has brought to light some important lessons. New malware attacks like this can take down your entire environment. Learn from others mistakes on how to prevent Petya like worms.

Question has a verified solution.

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

This article explains how to create forms/units independent of other forms/units object names in a delphi project. Have you ever created a form for user input in a Delphi project and then had the need to have that same form in a other Delphi proj…
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…
In this video we outline the Physical Segments view of NetCrunch network monitor. By following this brief how-to video, you will be able to learn how NetCrunch visualizes your network, how granular is the information collected, as well as where to f…
In this video, Percona Solution Engineer Rick Golba discuss how (and why) you implement high availability in a database environment. To discuss how Percona Consulting can help with your design and architecture needs for your database and infrastr…
Suggested Courses
Course of the Month8 days, 1 hour left to enroll

765 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