Solved

hack the VK_LEFT or VK_Right keys

Posted on 2001-07-05
11
358 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
Industry Leaders: 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

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

Creating an auto free TStringList The TStringList is a basic and frequently used object in Delphi. On many occasions, you may want to create a temporary list, process some items in the list and be done with the list. In such cases, you have to…
In my programming career I have only very rarely run into situations where operator overloading would be of any use in my work.  Normally those situations involved math with either overly large numbers (hundreds of thousands of digits or accuracy re…
Nobody understands Phishing better than an anti-spam company. That’s why we are providing Phishing Awareness Training to our customers. According to a report by Verizon, only 3% of targeted users report malicious emails to management. With compan…

730 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