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 strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Query regarding Virtual Key usage

Status
Not open for further replies.

CHeighlund

Programmer
Jun 11, 2007
163
US
While attempting to solve my previous problem (tab order for a form made in a rather unusual form, with components placed on in a strange order), I stumbled on the virtual key (VK_) information in the help field.

A test run on a dummy project showed me how to get those working, but using the same code on the original project doesn't want to work; I'm getting the error message "Undeclared Identifier: 'VK_TAB'" at the line reading "if(Key = VK_TAB) then" in my code for the KeyDown event.

The only thing I can think of is that the original project was, I belive, written in the CLX environment. Where would be a good place for me to start looking for equivalents to the VK_ keys for that?
 
Never mind, I apparently hit the idiot button before I started. CLX doesn't include the 'Windows' package(?) by default, so of course it didn't register.

However, I have included that now, but the program doesn't seem to be registering the key. Other keys trigger the KeyDown and KeyUp events on the component I started with, but pressing the tab button doesn't; it simply causes focus to jump to the next tabstopped component. I've tested this with breakpoints on the first (valid) statement in the KeyUp and KeyDown events - these breakpoints are never touched when the tab key is pressed. Any clues as to what I'm doing wrong?
 

I use the following in the OnKeyDown event, and it works for me:
Code:
if key in [VK_F1] then etc

Hope this helps.


Steve (Delphi 2007 & XP)
 

Posted that while you were typing yours it seems...

That was in response to query on VKs.

Have you set TabStop to false on your components/form?
That may be intercepting your code.

I use this in OnKeyPress event to act upon RETURN, may also work for tab if not getting bypassed:
Code:
  if key = #13 then     //look for ENTER pressed
    begin
      key := #0;
      my stuff here;
    end;



Steve (Delphi 2007 & XP)
 
Still nothing, although I thank you for the advice.

Again, its as if pressing the tab key doesn't trigger the KeyDown or KeyUp events - I've got identical code in both of them, just to see whether or not it behaves for either one. So far, both events can't seem to see the 'press tab' even though they do pass their focus on.
 
Pressing tab is trapped by windows (or OS) and typically jumps to the next control. To trap the event in those cases, I usually use the OnExit event. In the code, I manually add ActiveControl:= (); to force it to go where I want.

HTH

Roo
Delphi Rules!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top