Solved

hack the VK_LEFT or VK_Right keys

Posted on 2001-07-05
11
354 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
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 
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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
proper way to parse url in delphi 2 163
Virtuailstring tree compare node issue 14 105
When i run adoquery my application freezes 26 150
Firemonkey android show image from resource ? 1 33
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…
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…
Windows 10 is mostly good. However the one thing that annoys me is how many clicks you have to do to dial a VPN connection. You have to go to settings from the start menu, (2 clicks), Network and Internet (1 click), Click VPN (another click) then fi…
Video by: Mark
This lesson goes over how to construct ordered and unordered lists and how to create hyperlinks.

920 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

16 Experts available now in Live!

Get 1:1 Help Now