Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations bkrike on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Code to use Key_Home, etc....

Status
Not open for further replies.

abrogard

Technical User
Sep 13, 2002
58
AU
I am trying to intercept Keystrokes and respond to them with graphics and sound displays.

I've got it working okay for the Alpha keys (A...Z) with OnKeyPress and I've read in Help that apparently I can use the key codes Key_Left etc., and the events OnKeyDown and OnKeyUp to catch all the other keys.

But I can't discover how to code it up! 'If Key = Key_Left ...' etc. doesn't work and I can't stumble across nor find a demo of what will work.

Can someone please help me with a sample piece of code?

regards,
ab
 
the key codes are prefixed with 'VK_'

like this :

Code:
 ...
 case Key of
  
  VK_F1 : ShowHelp;
  VK_TAB : DoSomething;
  VK_ENTER :
   begin
    showmessage('you pressed enter!');
   end;
 end;
 ...

--------------------------------------
What You See Is What You Get
 

By god you're right. I just tried it and it works wonderfully. thanks a heap. :)

I wonder, was that information in the Delphi Help screens somewhere?

And I didn't know about that slick easy 'showmessage' either.

Thanks again.

regards,

ab
 
np m8, and yes you can find all this little info in the help system, altough a good book about delphi can do wonder :))

--------------------------------------
What You See Is What You Get
 
abrogard,

If you search in the Delphi help for "Virtual Key Codes", you'll find all of the VK_ constants (VK = "Virtual Key").

-Dell
 

Thankyou guys. Yes, I found the 'virtual keys' in Help once I knew they were there. There's an almost identical listing in Help for keycodes which lists them simply as 'Key_Home' and so on.... Most confusing to me.

I'm not quite sure but I think all the keys are not covered by the virtual codes... right? I'm not at that machine right now but I think I struck a key or two which didn't have a virtual code. What do we do in such a case?

And I'd be interested to know the numeric value returned by these 'constants', these virtual keys. Can I find that listing somewhere? Or get a little piece of code that will supply the number for each key as it is pressed? Ought to be able to write it myself, I know, but I'm history, I was once a programmer but that was before OOPs and years of User Support... I'm history nowadays... struggling to make a start with Delphi :) :)

I appreciate all the help you guys are giving.

ab


 
Look for "Virtual-Key Codes" in the Win32SDK help file that comes with Delphi - that has the codes and the numbers.

-Dell
 
Haven't got it, mate. Got this machine from a friend, sort of inherited it, and it's got some great stuff on it but much of it is missing this or that... and there's no disks attached to it, what i see is what I get and that's it... and the win32sdk doesn't seem to be installed any more than the msdn stuff is.... gotta work around it... :)
 

yep, thanks. when I get broadband I guess I'll make much use of it :).
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top