Solved

Detect keyboard tab key in Borland C++

Posted on 2010-11-11
2
1,818 Views
Last Modified: 2013-12-09
I have been trying to detect VK_TAB using OnKeyDown(TObject *Sender, WORD &Key, TShiftState Shift), however, i found that it can detect all keys on my keyboard but VK_TAB.
btw, i'm using Borland C++. Can anyone help please?
0
Comment
Question by:elvjac
[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
2 Comments
 
LVL 25

Accepted Solution

by:
kode99 earned 250 total points
ID: 34125911
The problem is that the tab key message is being trapped and used before you get to the point of a OnKeyDown event in any control or form.  

The simplest way to get around this is to catch the event through the TApplication events by setting a OnMessage handler.  The TApplication message handler sees the events before they are trapped by forms and controls.

So in your main form setup add a line,

  Application->OnMessage = AppMessage;

and create a function,

void __fastcall TForm1::AppMessage(tagMSG &Msg, bool &Handled)
{
  if( Msg.message == WM_KEYDOWN)
  {
    if(Msg.wParam == VK_TAB)
    {
      < do stuff here with the tab keystroke as desired>
      Handled = true;     // this will stop the message here 
    }
  }
}

Open in new window


Keep two things in mind.  First this AppMessage function will be in the loop for all processing of your program so make sure you do not slow things down.  

Secondly you will probably want to also check what form and control has focus so you can handle the tab key for the situation.  If you set Handled to true the message will not be passed any further.

Check the help on the TApplication.  Its automatically created for CBuilder apps and has some very useful functionality.
0
 
LVL 16

Expert Comment

by:George Tokas
ID: 34127265
You can use:
 if(GetAsyncKeyState(VK_TAB) != 0 )
{
//
}
I mentioned that at:
http://www.experts-exchange.com/Programming/Editors_IDEs/C_CPP_CS/CPP_Builder/Q_21147788.html
You can use it inside IdleLoop function.

George Tokas.
0

Featured Post

[Live Webinar] The Cloud Skills Gap

As Cloud technologies come of age, business leaders grapple with the impact it has on their team's skills and the gap associated with the use of a cloud platform.

Join experts from 451 Research and Concerto Cloud Services on July 27th where we will examine fact and fiction.

Question has a verified solution.

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

If you are having problems installing printer drivers, or if documents repeatedly get stuck in the print queue even after re-installing the printer drivers, then follow these steps to solve the problems. Please note that the steps are shown both for…
It started not too long ago. It was at first annoying. My keystrokes seemed to be randomly generated, not the ones I typed on the keyboard. For some reason this only happened in certain applications (especially browsers such as IE11, Firefox and Chr…
The viewer will learn how to use and create keystrokes in Netbeans IDE 8.0 for Windows.
The viewer will learn how to use and create new code templates in NetBeans IDE 8.0 for Windows.

615 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